echo returns "\" instead of "'"

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
r3curse
Forum Newbie
Posts: 7
Joined: Sun Nov 16, 2003 1:08 am

echo returns "\" instead of "'"

Post by r3curse »

I make use of a contact form on my (future) site, and when the user hits submit, I use echo to output the message sent to my email, but, whenever there's a word with a "'" in it (can't, don't etc..) php echoes it as a "\", so instead it looks like this: don\t, can\t etc..

how do I work around that?

-----------------------------------
<?php $to = "you@me.not";

$message = $message;

mail ($to, $subject, $message);

echo("<strong>THANK YOU!</strong>
<br>The following message was sent:
<br><br><strong>to:</strong><br>
<a href=\"http://www.notyet.no\" class=\"nonbold\">notyet.no</a><br><br>
<strong>message:</strong><br>
$message\n");?>
-----------------------------------

I'm not a stable coder, so don't make fun of my php-code :)

Any help would be greatly appreciated!
Thank!

Best retards,
r3curse
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Code: Select all

<?php

$to = "you@me.not";

$message = $_POST['message']; // i'm sure it came from a form
$message = str_replace("", "'", $message);

mail($to, $subject, $message);

echo <<< HERE
   <strong>
      THANK YOU!
   </strong>

   <br />
      The following message was sent:

   <br /><br />

   <strong>
      to:
   </strong>

   <br />

   <a href="http://www.notyet.no" class="nonbold">
      notyet.no
   </a>

   <br /><br />

   <strong>
      message:
   </strong>

   <br />

      $message

HERE;

?>
Not 100% sure but that might work,

-Nay
r3curse
Forum Newbie
Posts: 7
Joined: Sun Nov 16, 2003 1:08 am

Post by r3curse »

well, almost :)
it returns the following:

don''t etc

hehe
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

stripslashes(); is what you need to use :) .
r3curse
Forum Newbie
Posts: 7
Joined: Sun Nov 16, 2003 1:08 am

Post by r3curse »

uh, like this I guess:

Code: Select all

$message = stripslashes($message);
:)
r3curse
Forum Newbie
Posts: 7
Joined: Sun Nov 16, 2003 1:08 am

Post by r3curse »

yay!

thanks a bunch, qads :)
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

i am surprised Nay didnt tell you that, what you been smoking Nay? :lol:
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

your stuff O_O...............you sold me the wrong stuff dude

-Nay
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

lol, you should've known it was just plain old, dried up grass!
r3curse
Forum Newbie
Posts: 7
Joined: Sun Nov 16, 2003 1:08 am

Post by r3curse »

anyways... thanks :)
Post Reply