annihilate Posted March 29, 2006 Share Posted March 29, 2006 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 &p=7 in the source code. Anyone know if it could be put inside the eregi_replace somewhere.ThanksColin Quote Link to comment https://forums.phpfreaks.com/topic/6128-using-htmlspecialchars-inside-eregi_replace/ Share on other sites More sharing options...
Guest footballkid4 Posted March 30, 2006 Share Posted March 30, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/6128-using-htmlspecialchars-inside-eregi_replace/#findComment-22136 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.