Results 1 to 2 of 2
  1. #1

    Thread Starter
    No place like eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Blissful Oblivion

    [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
    Join Date
    Jan 2005

    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:

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

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.