Mailik Posted March 27, 2009 Share Posted March 27, 2009 Hey guys. I'm really sorry if this comes across as such a noob question. What it is, is that I have a basic shoutbox. And when I type in things such as "Didn't" It appears as "Didn/'t" And I'm just wondering on how to fix it so that it doesn't do that, I thought about a filteration where when people did typed " ' " it would replace " ' " with nothing. But felt that this wasn't resolving the problem, maybe shoving it aside. And even if it did fix the problem, I couldn't get it to work. Here is what I have, any help would be greatly appreciated. <?php $name = $_POST['Name']; $email = $_POST['Email']; $comments = $_POST['Comments']; $timedate = date("M d, Y (g:i a)", time() + 7200); if ($name == "" or $comments == "") { echo "Your name or comment was left blank! Try again. <br /><br />"; } else { $oldinfo = file_get_contents("data.txt"); $guestbookdata = fopen("data.txt", "w+"); fwrite($guestbookdata, "<table><td><div class=\"post\"><b>Name:</b> <a href=\"mailto:{$email}\">{$name}</a> <br> <b>Time:</b> <em>{$timedate}</em> <br />\n"); fwrite($guestbookdata, "<b>Comments:</b><br> $comments <br><br></td></table></div>\n \n"); fwrite($guestbookdata, "$oldinfo"); fclose($guestbookdata); } ?> Quote Link to comment Share on other sites More sharing options...
Brian W Posted March 27, 2009 Share Posted March 27, 2009 Add this to the top of the page. Let us know what happens. <?php if(get_magic_quotes_gpc() != 0){ die("Magic quotes is on!"); } else { echo "not the problem"; } ?> Quote Link to comment Share on other sites More sharing options...
irkevin Posted March 27, 2009 Share Posted March 27, 2009 wouldnt this be fine using strislashes? Quote Link to comment Share on other sites More sharing options...
Brian W Posted March 27, 2009 Share Posted March 27, 2009 assuming that magic_quotes_gpc is on, then yes, you'd use stripslashes() like so $name = stripslashes($_POST['Name'] $email = stripslashes($_POST['Email'] $comments = stripslashes($_POST['Comments'] Quote Link to comment Share on other sites More sharing options...
irkevin Posted March 27, 2009 Share Posted March 27, 2009 wow i never knew that stipslashes depends on magic_quotes_gpc :s ... in this case, i believe most servers have this on by default.. If im not mistaken.. Quote Link to comment Share on other sites More sharing options...
Mailik Posted March 27, 2009 Author Share Posted March 27, 2009 Hi, thanks for helping out. I added the code that you gave me and get the message 'Magic quotes is on!' So I tried using the stripslashes code afterwards that you had posted. So the code I have now looks like; <?php $name = stripslashes($_POST['Name'] $email = stripslashes($_POST['Email'] $comments = stripslashes($_POST['Comments'] $timedate = date("M d, Y (g:i a)", time() + 7200); if ($name == "" or $comments == "") { echo "Your name or comment was left blank! Try again. <br /><br />"; } else { $oldinfo = file_get_contents("data.txt"); $guestbookdata = fopen("data.txt", "w+"); fwrite($guestbookdata, "<table><td><div class=\"post\"><b>Name:</b> <a href=\"mailto:{$email}\">{$name}</a> <br> <b>Time:</b> <em>{$timedate}</em> <br />\n"); fwrite($guestbookdata, "<b>Comments:</b><br> $comments <br><br></td></table></div>\n \n"); fwrite($guestbookdata, "$oldinfo"); fclose($guestbookdata); } ?> When I go to post, I get the error "Parse error: parse error in post.php on line 5" Quote Link to comment Share on other sites More sharing options...
irkevin Posted March 27, 2009 Share Posted March 27, 2009 the semicolumn should be after $name = stripslashes($_POST['Name']); $email = stripslashes($_POST['Email']); $comments = stripslashes($_POST['Comments']); Quote Link to comment Share on other sites More sharing options...
Brian W Posted March 27, 2009 Share Posted March 27, 2009 stripslashes() is not dependent on it, its a way of neutralizing the effects of it. If magic_quotes_gpc is off, you wouldn't need to use strip slashes (in this case) but strip slashes would still work on a string. Sorry I sent you the code with the ")" outside the semicolon. Need more coffee or new glasses, or both :-) Quote Link to comment 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.