[thelist] [php] preg_replace text links?

kris burford kris at midtempo.net
Mon Nov 3 04:42:25 CST 2003


>>what i'm trying to do is scan user submitted text (parsed through 
>>htmlspecialchars) pick out any links and link 'em up.
>
>$a=preg_replace("/(http:\/\/|www|[a-zA-Z0-9-]+\.|[a-zA-Z0-9\.-]+@)(([a-zA-Z 
>0-9-][a-zA-Z0-9-]+\.)+[a-zA-Z0-9-\.\/\_\?\%\#\&\=\;\~\!\(\)]+)/","<a 
>href=\"http://\\1\\2\">\\1\\2</a>",$a);
>
>that extracts most links and creates HTML links.

this is great, unless they include "http://" in their text (which then 
results in: <a href="http://http:// ...)

kris



More information about the thelist mailing list