SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru DeNasio's Avatar
    Join Date
    May 2001
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $string = eregi_replace("\"","#34;",$string);

    Hello guys,

    I have the following code in my script:

    Code:
    $string = eregi_replace("\"","#34;",$string);
    But all ' " ' are being replaced by '\#34;'.
    I dont understand why it adds the "\" character!!
    Am I doing something wrong here?

    P.S. I did not put the "&" sign in front of "#34;"!
    But in my script I did put the "&" in front of the "#34;"

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Where does $string come from? A Form? Is it possible you have magic_quotes_gpc = On in your php.ini which would automatically add a slash before quotes in $string once the form was posted, if this is the case then the slash was there before the eregi_replace.

    BTW str_replace is much faster here because you don't need a regular expression all you want to do is change " to #34 right?


    $string = str_replace('"',"#34;",$string);

    To rid yourself of the slashes

    $string = str_replace('"',"#34;",stripslashes($string));
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Guru DeNasio's Avatar
    Join Date
    May 2001
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Where does $string come from? A Form?
    Yep, from a form. I think you are right about the 'magic_quotes_gpc = On' stuff.

    Thanks.


Bookmarks

Posting Permissions

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