PDA

Click to See Complete Forum and Search --> : [PHP] Preg_relpace ampersand ( & ) with &


eyeRmonkey
Jan 17th, 2007, 03:08 AM
With the help of the wonderful Penagate, I was able to solve a problem I had when dealing with improper ampersands on certain websites.

The problem was that some sites doesn't escape their ampersands (&) with &. Here is a small line of code that will replace all & with & without messing up other html-encoded entities such as < etc.

$body = preg_replace('/&(?![#]?[a-z0-9]+;)/i', "&$1", $body);

penagate
Apr 8th, 2008, 11:42 PM
In case the one provided here is insufficient, here is a far more complex expression to perform the same task:
http://regexadvice.com/blogs/mash/archive/2005/01/26/323.aspx