How Do I Escape Characters in PHP?

Discussion in 'PHP' started by timallard, Jan 31, 2008.

  1. #1
    Hello,

    I have a bunch of text fields and when ever anyone enters in an apostrophe my output is e.g "Valentine/'s Day" and not "Valentines Day".

    I know its simple,.. >.<

    I forget how to escape it correctly.
    All help is appreciated.

    Thank You,
    -Tim
     
    timallard, Jan 31, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    The apostrophe is actually escaped already. You want to unescape it. You can do that using stripslashes().

    Or wait... do you want to remove the apostrophe? If that's the case, use str_replace().
     
    nico_swd, Jan 31, 2008 IP
  3. timallard

    timallard Well-Known Member

    Messages:
    1,634
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    158
    #3
    +Rep, thank you. (edit:sorry, i cant rep you, because I did in the past 30 days. but thanks!)
     
    timallard, Jan 31, 2008 IP
  4. lslars31

    lslars31 Peon

    Messages:
    260
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    yea it's strip_slashes(); to remove the forward slashes
     
    lslars31, Jan 31, 2008 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    They're backslashes, and it's stripslashes(), without the underscore. :p
     
    nico_swd, Jan 31, 2008 IP
  6. lslars31

    lslars31 Peon

    Messages:
    260
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    ok you got me haha, I always add the "_" when I use it and realize it's wrong. Maybe I will learn one of these times. According to what he has up there it's a forward slash... I was kinda thinking the same thing but was too lazy to check. :D
     
    lslars31, Jan 31, 2008 IP