Конвертирование ссылок в тексте в гипертекст

В редакторе

Конвертирование ссылок в тексте в гипертекст

Brain_Script
3435
2020-02-07 07:50:24
function url_to_link($text){ $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; // Проверка текста на наличие url if (preg_match_all($reg_exUrl, $text, $url)) { foreach($url[0] as $v){ $position = strpos($text,' '.$v)+1; $text = substr_replace($text,'', $position, strlen($v)); $text = substr_replace($text,''.$v.'', $position ,0); } return $text; } else { // Если нет url-ов возвращаем текст return $text; } } $string = 'This is a string of text and we have a link: http://papermashup.com we also have another link http://google.com'; echo url_to_link($string);
Войдите для добавления комментария.
Нет комментариев
Яндекс.Метрика Яндекс.Метрика