안녕하세요. URL 텍스트를 링크로 성공적으로 변경할 수 있지만 URL이없는 텍스트를 표시하는 데 문제가 있습니다. preg_replace는 URL이없는 텍스트를 표시하지 않습니다.
시도하고 도와 호야 시도 해 봤나 ... 거기에 URL을하지 않는 것은preg_replace
을 사용하기 전에
preg_match
으로 테스트 할 필요가 없습니다
<?php
$textorigen = $row_get_tweets['tweet'];
// URL starting with http://
$reg_exUrl = "/(^|\A|\s)((http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,4} (\/\S*)?)/";
if(preg_match($reg_exUrl, $textorigen, $url)) {
// make the urls hyper links
$text_result=preg_replace($reg_exUrl, "$1<a href=\"$2\">$2</a> ", $textorigen);
$textorigen=$text_result;
} else {
// if no urls in the text just return the text
$text_result=$textorigen;
}
// URL starting www.
$reg_exUrl = "/(^|\A|\s)((www\.)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,4}(\/\S*)?)/";
if(preg_match($reg_exUrl, $text_result, $url)) {
// make the urls hyper links
$text_result=preg_replace($reg_exUrl, "$1<a href=\"http://$2\">$2</a>", $text_result);
$textorigen=$text_result;
echo $textorigen;
}
?>
가 대단히 감사합니다 .. 초보자가 코드를 사용해 보았습니다 .couldn't는 일할 수 있습니다. 어떻게 사용합니까? 감사합니다. – user3813986
@ user3813986 : 예제 코드를 추가하겠습니다. –
알겠습니다 감사합니다 기다리고있을 것입니다 – user3813986