Getting rid of escaped ' in email

Posted on 2011-04-21
Medium Priority
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.
Question by:steva

Expert Comment

ID: 35442749
LVL 12

Expert Comment

by:Mohamed Abowarda
ID: 35442850
You can get rid of any char by using str_replace():

$char = "'";
$str = str_replace($char, '', $str);

Open in new window

LVL 12

Expert Comment

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

Open in new window

LVL 111

Accepted Solution

Ray Paseur earned 2000 total points
ID: 35447764
Your PHP installation has magic quotes turned on.  You do not want that.  Please see the man page here:

So you can use the stripslashes() function or you can do the recommended thing and stop using the deprecated "feature" -- I would opt for the latter.  Magic Quotes was an early attempt by the PHP authors to make the language so easy to use that anyone, even someone with no understanding of computer science or data base requirements, could write PHP programs.  Along with "register globals" it has turned out to be a poor choice for a variety of reasons.

After you turn off magic quotes, you will want to be certain to use the appropriate escape mechanisms to prepare data for use in queries, like mysql_real_escape_string()

Author Closing Comment

ID: 35448897

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses
Course of the Month14 days, 15 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question