I need help converting eregi_replace to preg_replace (since in PHP5 it’s depreciated):
function makeClickableLinks($text)
{
$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'<a href="\\1">\\1</a>', $text);
$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'\\1<a href="http://\\2">\\2</a>', $text);
$text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})',
'<a href="mailto:\\1">\\1</a>', $text);
return $text;
}
(It turns text links and emails into hyperlinks so that the user can click on them)
Start with a look at the list of differences between POSIX and PCRE expressions in the manual.
If your expressions aren’t complicated, generally it means that you can get away with simply putting delimiters around your
$patternparameter, and switch to use thepregfamily of functions. In your case, you would do this:Note the
/characters around your patterns, and theiflag after the delimiters. I tested this quickly, and it worked for a basic URL. You’ll probably want to test it more thoroughly.