Hello all,

Well, I'm having problems again.  This time with string replacement.  I'd
like people to be able to write notes on one of the site's I'm helping with,
and would like them to be able to use Bold, Italic, Underline and <a href>
tags.  I tried using striptags(); but that would strip anything within
double quotes too.  So I've gotten around it by converting the message
string to htmlspecialchars and then using ereg_replace around the tags I'd
like to allow, ie:

$message = ereg_replace("&lt;u&gt;","<u>", $message);

Where I'm struggling is with the a href tags, though.  I've been using this:

$message = eregi_replace("(&lt;a
href=&quot;)(http://[^[:space:]]{1,})(&quot;&gt;)(.*)(&lt;\/a&gt;)", "<a
href=\"\\2\" target=\"_blank\">\\4</a>", $message);

which would change a string containing:
<a href="http://www.php.net">PHP!</a>
to:
<a href="http://www.php.net" target="_blank">PHP!</a>

Great.  But, there's a problem.  If someone uses:
<a href="http://www.php.net" target="_blank">PHP!</a><a
href="http://www.php.net" target="_blank">PHP Again!</a>
it returns:
<a href="http://www.php.net" target="_blank">PHP!/a&gt;&lt;a
href=&quot;http://www.php.net&quot;PHP AGAIN!</a>

Ouch!

Anyone got any ideas where it's going wrong?

Also, for the html that isn't allowed, it'd be nice to have some sort of
cleanup, so that something like this:

<blah>BLAH</blah>

Would be returned as BLAH.  But not essential :)

Thanks in advance,

James.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to