We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Getting rid of escaped ' in email

steva
steva asked
on
Medium Priority
228 Views
Last Modified: 2012-05-11
I have a form with a textarea input to let the customer enter comments. The PHP code  that processes the form puts the string from the textarea into the body of an email and sends it to me.

The problem is that if the client enters an apostrophe ( ' ), as in "Here's a new order"  it shows up in the email I get as " Here\'s a new order."

Does anyone know how I can get rid of the \  in the email?

Thanks for any help.
Comment
Watch Question

Mohamed AbowardaSenior Software Engineer
CERTIFIED EXPERT

Commented:
You can get rid of any char by using str_replace():

http://php.net/manual/en/function.str-replace.php
$char = "'";
$str = str_replace($char, '', $str);

Open in new window

Mohamed AbowardaSenior Software Engineer
CERTIFIED EXPERT

Commented:
You can also try to double the quotation by using the following code:
$str = str_replace("'", "''", $str);

Open in new window

Most Valuable Expert 2011
Author of the Year 2014
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.