php rexp a-z www a-z0-9- a-z0-9 a-z0-9 a-z0-9- com net org w- punct te

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
<?php
$rexp = '/\b(?:'.
'(?:[a-z]+:\/\/|www\.)(?:[a-z0-9-]+\.)*[a-z0-9]+'.
'|'.
'(?:[a-z0-9][a-z0-9-]*\.)+(?:com|net|org)(?![\w-])'.
')\S*'.
'(?:(?<![[:punct:]])|(?<=[-\/&+*]))/';
$test_text = 'http://www.pogoda.in/new_york/eng/ php.net/docs www.pogoda.in test';
$text = preg_replace($rexp, '<a href="$0">$0</a>', $test_text);
echo $text;
?>
результат
<a href="http://www.pogoda.in/new_york/eng/">http://www.pogoda.in/new_york/eng/</a> <a href="php.net/docs">php.net/docs</a> <a href="www.pogoda.in">www.pogoda.in</a> test