Jump to content


Using htmlspecialchars inside eregi_replace

  • Please log in to reply
1 reply to this topic

#1 annihilate

  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts
  • LocationUK

Posted 29 March 2006 - 09:30 PM

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.

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.

Personal site: NewEnigma  |  Java and JSF Discussion

#2 Guest_footballkid4_*

  • Guests

Posted 30 March 2006 - 12:19 AM

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]

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users