Jump to content


This topic is now archived and is closed to further replies.


Using htmlspecialchars inside eregi_replace

Recommended Posts

I have this function that I found on the net for converting urls posted in a string into hyperlinks when they are printed to the browser.

[code]function make_links($text)
$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '<a href="\\1" target="_blank">\\1</a>', $text);
$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '\\1<a href="http://\\2" target="_blank">\\2</a>', $text);
return $text;
Problem is I want to make the urls produced xhtml valid, so I want to apply htmlspecialchars or htmlentities to the links so that urls with &p=7 for example are turned into &amp;p=7 in the source code.

Anyone know if it could be put inside the eregi_replace somewhere.


Share this post

Link to post
Share on other sites
Guest footballkid4
preg_replace_callback() is your friend.
[a href=\"http://us3.php.net/manual/en/function.preg-replace-callback.php\" target=\"_blank\"]http://us3.php.net/manual/en/function.preg...ce-callback.php[/a]

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.