How do I escape quotes in preg_match?

Discussion in 'PHP' started by learnwebsitedesigncom, Aug 24, 2011.

  1. #1
    Hi everyone, how do I allow the use of single and double quotation marks in the code below?

    Thanks

    
     else if(preg_match('/[^a-zA-Z0-9?! .-]/', $message)){
      echo '<h2>Enter a valid message.</h2>';
     }
    
    Code (markup):

     
    learnwebsitedesigncom, Aug 24, 2011 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    Just escape them \'\"
    
     else if(preg_match('/[^\'\"a-zA-Z0-9?! .-]/', $message)){
      echo '<h2>Enter a valid message.</h2>';
     }
    
    Code (markup):
     
    MyVodaFone, Aug 24, 2011 IP
  3. learnwebsitedesigncom

    learnwebsitedesigncom Active Member

    Messages:
    264
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #3
    I've tried that but it's not working for some reason
     
    learnwebsitedesigncom, Aug 24, 2011 IP
  4. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #4
    Exactly what are you trying to match?
     
    Rukbat, Aug 24, 2011 IP
  5. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #5
    Would need to see the full code and an example $message
     
    MyVodaFone, Aug 24, 2011 IP