글쎄, 누군가가 메시지 상자에 텍스트가있는 링크를 넣으면 링크를 활성화하는 기능입니다.PHP 링크 활성
제 질문은 누군가가 많은 링크를 예 : www.yahoo.com www.gmail.com www.facebook.com에 넣으면 하나 이상의 링크가 표시되지 않습니다. 그런 다음 첫 번째 링크는 www.yahoo.com에만 표시됩니다.
function txt2link($text){
// force http: on www.
$text = ereg_replace("www\.", "http://www.", $text);
// eliminate duplicates after force
$text = ereg_replace("http://http://www\.", "http://www.", $text);
$text = ereg_replace("https://http://www\.", "https://www.", $text);
// The Regular Expression filter
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
// Check if there is a url in the text
if(preg_match($reg_exUrl, $text, $url)) {
// make the urls hyper links
$text = preg_replace($reg_exUrl, '<a href="'.$url[0].'" rel="nofollow">'.$url[0].'</a>', $text);
} // if no urls in the text just return the text
return ($text);
}
$url = "Alter pot waer it your pot http://css-tricks.com/snippets/php/find-urls-in-
text-make-links/ you may click the link www.yahoo.com or you may see what is the
http://www.youtube.com say, is it right?";
echo txt2link($url);
이 코드를 실행하면 결과를 확인할 수 있습니다.
아이디어가 있으십니까?
모르겠다. 오늘 혼자서, 텍스트에서 URL을 추출하려고 시도한 비슷한 (그러나 다른!) 정규 표현식을 가진 12 명의 사람들을 보았습니다. 왜 이런 일이 생길까요? PHP'get_urls' 패키지의 개발자가 돈으로 가득 찬 수영장에서 수영을할까요? – Borealid
내가 말할 것 인 첫번째 물건은 preg에 찬성하여 도랑 ereg 다, 지금 잠시 동안 비참하게하게되었다. – quickshiftin
js를 사용하여이 클라이언트 사이트를 만드는 것에 대해 생각해 본 적이 있습니까? http://benalman.com/code/projects/javascript-linkify/docs/files/ba-linkify-js.html – Flukey