Results 1 to 2 of 2

Thread: [PHP] Preg_relpace ampersand ( & ) with &

  1. #1

    Thread Starter
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    [PHP] Preg_relpace ampersand ( & ) with &

    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.

    PHP Code:
    $body preg_replace('/&(?![#]?[a-z0-9]+;)/i'"&$1"$body); 
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [PHP] Preg_relpace ampersand ( & ) with &

    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/ar...01/26/323.aspx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width