How about you decode the string, and then encode it like so: $decode = html_entity_decode($input); $output = htmlentities($decode);
If you have the string ab&something&blah the decode will turn that into ab&something&blah and then encode it into ab&something&blah This can run into problems, but they will be just the same problems you would receive with any other method... The problem I speak of is when your input string is "something&" and & isn't a HTML Entity but the proper string just so happened to have a & in it just before the amp... In that case the amp; would be incorrectly removed... However the chances of having a string that matches a HTML entity with a "bad" & placed in front of it are so high that you shouldn't worry (and you did mention it was a URL, so as far as I know ; can't appear in a valid URL, so I don't think you should worry at all :))... And if you are worrying then any method you chose will have this problem and you should do the task by hand :) Hope this helps Andrew ----- Original Message ----- From: "Shawn McKenzie" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Sunday, July 27, 2003 8:36 AM Subject: [PHP] replacing & but not special chars > I have some URLs in hrefs that have an &. This does not validate HTM4.01 > transitional, so I want to replace them with & > > So I buffer the output and do a replace, but suppose there is already an > & then I get &amp; or if I have anything else like " then I get > &quot; > > Any ideas on how to do this the right way??? > > Thanks! > Shawn > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php