41 users online (1 members and 40 guests)  


  Results 1 to 3 of 3

Related

  1. fixing the width of <td>    Forum: HTML Forum
    Replies: 2
  2. Fixing image to align bottom    Forum: CSS Forum
    Replies: 0
  1. #1
    Takshaka's Avatar
    New User

    Status
    Offline
    Join Date
    Feb 2006
    Posts
    1

    Question Fixing unescaped ampersands

    I've got a MySQL db which has unescaped ampersands (&) which need fixing without changing any properly escaped ampersands and other entities which are present - ie I need to change & to &amp; without changing &amp; to &amp;amp; or ń to &amp;#324;.

    I thought I'd be able to do it with a regular expression in a MySQL query but it seems this won't work as MySql doesn't support negative lookaheads in regular expressions.

    Any suggestions as to how this could be achieved would be very welcome!

    Thanks

  2. #2
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    record

    I've tried this in PHP and it seems to work fine ...
    With the record to be corrected stored in $record:

    PHP Code:
    $correct "";
    for (
    $c 0$c strlen($record); $c++) {
      
    $add "";
      if (
    substr($record,$c,1) == "&"
        
    and substr($record,$c,5) != "&amp;"
        
    and substr($record,$c,2) != "&#") {
          
    $add "amp;";
      }
      
    $correct .= substr($record,$c,1).$add;

    The correct string should not be stored in $correct, ready to be updated back into your database.
    Last edited by DeadMeatGF; 02-23-2006 at 11:04 AM.

  3. #3
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: record

    Just noticed a typo -the last line above should read ".. should now be stored ..."
    Sorry!



Tags for this Thread