Jump to content

quick echo question...


theredking

Recommended Posts

I have an echo that presents the content of a text box from a form. Trouble is, if within that text area someone types an apostrophe, for example "Owner's" it is echoed as such "Owners\'s"

 

How can I stop it adding in the additional "\" character?

 

Here's the code

<?php echo ("$line1"); ?>

 

 

Link to comment
Share on other sites

MadTechie and thorpe, thank you for your replies. The following fixed the problem...

 

echo htmlentities(stripslashes($line1), ENT_QUOTES);

 

thorpe what do you mean by magic quotes? Is there something else I should look for?

 

Also MadTechie, I didn't add the "stripslashes()" that you suggested because I wasn't sure where to put it, but it works regardless. Should I still try to put that somewhere?

 

Thanks again both of you. I really appreciate your help.

Link to comment
Share on other sites

??? Ok, one more quick question...

 

The contents of this form is also being emailed to me, and I'm having the same problem with the email results. Here's the code... I tried adding your suggestions to this code, but I'm afraid I'm a bit too green still to work it out properly. It's the $line1 and $line2 variables that are affected.

 

Thanks again if you get the time...

 

<?php   
   
  }
  else {

  mail( "me@myemail.com", "Subject",
    "$title $name\n$address\n$city, $state, $zip\nPhone Number: $phone\nCell Phone: $cell\n$email\n\nStar Size: $star\n\nEngraving will read...\n\n$line1\n$line2", 
"From: $name <$email>" );

}	

if ($star == "4 inch $150"){

?>	

 

 

Link to comment
Share on other sites

Me again, sorry...

 

I added what you suggested before the "mail(" like so:

 

<?php   
   
      
  }
  
  
  else {

$line1=htmlentities(stripslashes($line1), ENT_QUOTES);
$line2=htmlentities(stripslashes($line2), ENT_QUOTES);

  

  mail( "me@myemail.com", "Email Subject",
    "$title $name\n$address\n$city, $state, $zip\nPhone Number: $phone\nCell Phone: $cell\n$email\n\nStar Size: $star\n\nEngraving will read...\n\nhtmlentities(stripslashes($line1), ENT_QUOTES);\n$line2", 
"From: $name <$email>" );

}	

if ($star == "4 inch $150"){

?>	

 

and it turned all the punctuation characters into html numbers... "&#39;" etc... So I thought maybe now I can change the echo statements back to the simple "echo $line1"

 

This fixed the echo displays, but meant the email now displayed:

 

htmlentities(stripslashes(Mr Test&#039;s), ENT_QUOTES);

<<item>>

 

Instead of:

 

Mr Test's

<<item>>

 

I then put what you suggested at the start of that php statement, and that gave me back my "\" in the echo, but fixed the html numbers in the email, but left $line1 of the email as:

 

htmlentities(stripslashes(Mr Test's), ENT_QUOTES);

 

If I add back in your echo statement, it fixes the echo again, but changes the email to displaying as:

 

htmlentities(stripslashes(Mr Test\'s), ENT_QUOTES);

 

for the information in $line1

 

Note the return of "\"

 

 

Sorry if this is a terribly complicated post... Do you have any suggestions? Just to try and help my code now looks like this:

 

<?php   
   
    $line1=htmlentities(stripslashes($line1), ENT_QUOTES);
$line2=htmlentities(stripslashes($line2), ENT_QUOTES);

  
  }
  
  
  else {
  
   
  

  mail( "me@myemail.com", "Email Subject",
    "$title $name\n$address\n$city, $state, $zip\nPhone Number: $phone\nCell Phone: $cell\n$email\n\nStar Size: $star\n\nEngraving will read...\n\nhtmlentities(stripslashes($line1), ENT_QUOTES);\n$line2", 
"From: $name <$email>" );

}	

if ($star == "4 inch $150"){

?>	

<?php echo htmlentities(stripslashes($line1), ENT_QUOTES); ?>
<?php echo htmlentities(stripslashes($line2), ENT_QUOTES); ?>

 

Link to comment
Share on other sites

OK first off, this code is fine (well kinda)

 

<?php   
  } else {

$line1=htmlentities(stripslashes($line1), ENT_QUOTES);
$line2=htmlentities(stripslashes($line2), ENT_QUOTES);

  mail( "me@myemail.com", "Email Subject",
    "$title $name\n$address\n$city, $state, $zip\nPhone Number: $phone\nCell Phone: $cell\n$email\n\nStar Size: $star\n\nEngraving will read...\n\nhtmlentities(stripslashes($line1), ENT_QUOTES);\n$line2", 
"From: $name <$email>" );

}	

if ($star == "4 inch $150"){

?>	

 

basically the problem your facing is in the email, the reason your getting the > etc etc, is because of the email format.. (being plan text) to resolve this you need to tell the email client that the email contains html not just plan text..

 

to do this..

change the (in the mail function)

"From: $name <$email>"

"From:$name <$email>\r\nReply-to: $email\r\nContent-type: text/html; charset=us-ascii"

Link to comment
Share on other sites

I'm sorry, I'm an idiot, I see now what is wrong... I left the

 

"\n\nhtmlentities(stripslashes($line1), ENT_QUOTES);\n$line2""

 

in the:

 

mail( "me@myemail.com", "Email Subject",
    "$title $name\n$address\n$city, $state, $zip\nPhone Number: $phone\nCell Phone: $cell\n$email\n\nStar Size: $star\n\nEngraving will read...\n\nhtmlentities(stripslashes($line1), ENT_QUOTES);\n$line2", 
"From: $name <$email>" );

 

So obviously it was sending it through to me that way... Agggh

 

Actually though it will be very useful to have the email sent as html so I can style it a little nicer.

 

Thank you so much for your time. As always, two heads are better than one, and it was only when I saw you repost my code that I could see the error in it.

 

Regards,

 

Rory

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.