How to use stripslashes to clean up results from a form email

I’m new to php. Need some basic help. I have a contact form that works except I get results with slashes in front of every apostrophe. Need to know how to use stripslashes This form is using a function clean_string and I don’t know how to use stripslashes.

I’ll just address the comment section of the form and php here. Here’s the gist of my form in the html, just the comments section is what I’ll show:

and in the php file it’s handled with:

if(!isset($_POST['comments'])) {
    died('We are sorry, but there appears to be a problem with the form you submitted.');     

$comments = $_POST['comments']; // required

$email_message = "Form details below.\n\n";
function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
$email_message .= "Comments: ".clean_string($comments)."\n";

How do I fix? Thanks in advance.


simple enough

$comments = stripslashes($comment string goes here);

That clean function just cleans up the headers, has nothing to do with the actual message. You only want to run stripslashes on the comments and subject fields (or just comments of subject is hard coded).

So if I’m hearing you right, and the comments would be a string the web user enters in on the form text area with the label ‘comments’ then to strip the slashes out I would put:

$comments = stripslashes($comments)

That doesn’t work, I get error: Parse error: syntax error, unexpected T_VARIABLE in html_form_send.php on line 34

which is basically where that line is that I added, which I added right above the existing line:

$comments = $_POST[‘comments’]; // required

If there’s no mySQL involved, you don’t need to use it at all. But if there is, just put after the post variable.

Yes mysql is on the server for another project/business I have that a programmer is working on… That’s how the slashes get there apparently and so stripslashes is how I was told to have to handle it for this basic form.

So thank you for the reply. So I’m thinking now the line should look like this:

$comments = $_POST[’ stripslashes (comments)’]; // required

Right? Sorry but I don’t find any help on the syntax of this command, just statements of what it should do…

Its $comments = stripslashes($_POST[‘comments’]); // required

Worked like a charm!!! Thank you very much!!!

Sponsor our Newsletter | Privacy Policy | Terms of Service