从String替换URL

时间:2014-11-01 12:42:03

标签: php regex string

您好我试图从字符串中查找并替换任何类型的URL。我正在使用这个:

$content = <<<EOS
Link_1: [code]This is a textual line.
www.google.com
This is a textual line.[/code]

Link_2: [php]This is a textual line.
www.google.com
This is a textual line.[/php]
EOS;
$needle = '~(?:https?://)?(?:www\.)(?:[^.\s]+)(?:\.[^.\n\s]+)*\.\w{2,4}(?=(?:(?!\[/?(?:code|php)])[\S\s])*\[/(?:code|php)])~m';
echo preg_replace($needle,'LINK HIDDEN',$content);

但它没有奏效。它什么都不做,请帮忙

0 个答案:

没有答案