Jump to content

Using htmlspecialchars inside eregi_replace


annihilate

Recommended Posts

Hi,
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;
}[/code]
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.

Thanks
Colin

Archived

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

×
×
  • Create New...

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.