function makeLinksInTheContent($html)
{
$html= preg_replace("/(^|[\n ])([\w]*?)((ht|f)tp(s)?:\/\/[\w]+[^ \,\"\n\r\t<]*)/is", "$1$2<a href=\"$3\" rel=\"nofollow\" >$3</a>", $html);
$html= preg_replace("/(^|[\n ])([\w]*?)((www|ftp)\.[^ \,\"\t\n\r<]*)/is", "$1$2<a href=\"http://$3\" rel=\"nofollow\" >$3</a>", $html);
$html= preg_replace("/(^|[\n ])([a-z0-9&\-_\.]+?)@([\w\-]+\.([\w\-\.]+)+)/i", "$1<a href=\"mailto:[email protected]$3\" rel=\"nofollow\">[email protected]$3</a>", $html);
return($html);
}
이것은 내 코드입니다.preg_replace는 일치하는 URL의 문자열을 대체합니다.
내 URL이 자동으로 필요합니다. preg_replace를 사용하여 url을 찾고이 url에 대한 링크를 설정하십시오.
예 : '페이지에 www.google.com이 있습니다.' 이 콘텐츠를 makeLinksInTheContent ($ html)에 전달하면 "www.google.com이 포함 된 페이지"가 반환됩니다.
하지만 다음 URL 형식은 연결되지 않습니다.
www.test.com()와 [] &^%의 $의 # @ + | @ # $으로의 %^&() _ +} {! "? > <,./'[] = - 09 ~`.co, in, com.com
http://www.test.com() 및 [] &^% $ # @! + | ! @ # $ %^&() _ +} {: "?> <,. /; [] = - 09 ~`.co, in, com.com
https://www.test.com() 및 [] &^% $ # @! +!! @ # $ %^&() _ +} {: "?> <,. /; '[] = -09 ~`.co와, com.com
ftp://www.test.com()와 [] &^%의 $ 번호에 @ + |! @ # $으로의 %^&() _ +} {:?. "> <, /, '[] = - 09 ~`.co와, com.com
에 내가 생각하는 내 정규 표현식은 몇 가지 실수가 있습니다. 제발 우리를 제안하십시오.
출력 전에...? 이 EXACT 질문 – SmokeyPHP
[preg \ _replace가 일치하는 URL을 대체하는 문자열] 중복 됨 (http://stackoverflow.com/questions/17783918/preg-replace-to-replace-string-for-matching-url) – SmokeyPHP