theredking Posted August 23, 2007 Share Posted August 23, 2007 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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/66355-quick-echo-question/ Share on other sites More sharing options...
MadTechie Posted August 23, 2007 Share Posted August 23, 2007 try this <?php echo stripslashes($line1); ?> stripslashes() Quote Link to comment https://forums.phpfreaks.com/topic/66355-quick-echo-question/#findComment-331968 Share on other sites More sharing options...
theredking Posted August 23, 2007 Author Share Posted August 23, 2007 Thank you, that works! What I want it to do though is echo exactly what is input into the text area, no matter what that is. For example, if "><><Wow's><><<" is input, only "><><><<" is echoed. How do I tell it to do that? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/66355-quick-echo-question/#findComment-331975 Share on other sites More sharing options...
trq Posted August 23, 2007 Share Posted August 23, 2007 That shouldn't happen. Post your code. Quote Link to comment https://forums.phpfreaks.com/topic/66355-quick-echo-question/#findComment-331979 Share on other sites More sharing options...
MadTechie Posted August 23, 2007 Share Posted August 23, 2007 try this. echo htmlentities(stripslashes($line1), ENT_QUOTES); also what thorpe is saying it true, you have a filter somewhere, that added the slashes (probably addslashes) Quote Link to comment https://forums.phpfreaks.com/topic/66355-quick-echo-question/#findComment-331984 Share on other sites More sharing options...
trq Posted August 23, 2007 Share Posted August 23, 2007 also what thorpe is saying it true, you have a filter somewhere, that added the slashes (probably addslashes) Nah.. more than likely magic quotes. Damn them! Quote Link to comment https://forums.phpfreaks.com/topic/66355-quick-echo-question/#findComment-331991 Share on other sites More sharing options...
MadTechie Posted August 23, 2007 Share Posted August 23, 2007 Nah.. more than likely magic quotes. Damn them! See this is what i was saying before you love correcting me LOL JK Quote Link to comment https://forums.phpfreaks.com/topic/66355-quick-echo-question/#findComment-331994 Share on other sites More sharing options...
theredking Posted August 23, 2007 Author Share Posted August 23, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/66355-quick-echo-question/#findComment-331995 Share on other sites More sharing options...
theredking Posted August 23, 2007 Author Share Posted August 23, 2007 ??? 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"){ ?> Quote Link to comment https://forums.phpfreaks.com/topic/66355-quick-echo-question/#findComment-332007 Share on other sites More sharing options...
MadTechie Posted August 23, 2007 Share Posted August 23, 2007 add $line1=htmlentities(stripslashes($line1), ENT_QUOTES); $line2=htmlentities(stripslashes($line2), ENT_QUOTES); before you use them so before the mail( Quote Link to comment https://forums.phpfreaks.com/topic/66355-quick-echo-question/#findComment-332012 Share on other sites More sharing options...
theredking Posted August 23, 2007 Author Share Posted August 23, 2007 Thank you!! I'm learning fast. This forum is a great resource. Quote Link to comment https://forums.phpfreaks.com/topic/66355-quick-echo-question/#findComment-332020 Share on other sites More sharing options...
theredking Posted August 23, 2007 Author Share Posted August 23, 2007 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... "'" 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'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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/66355-quick-echo-question/#findComment-332213 Share on other sites More sharing options...
MadTechie Posted August 23, 2007 Share Posted August 23, 2007 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" Quote Link to comment https://forums.phpfreaks.com/topic/66355-quick-echo-question/#findComment-332220 Share on other sites More sharing options...
theredking Posted August 23, 2007 Author Share Posted August 23, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/66355-quick-echo-question/#findComment-332226 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.