Jump to content

[SOLVED] Newbie question - Removing the "\" from my blog scripts.


Recommended Posts

Hello.  Very new PHP programmer here.  I have zero experiences with regexes, which is why I'm making this thread. 

 

I programmed a very simple blog scripts and when someone types anything with an apostophre, then when it's submitted it comes out with a backslash in front of it.  Example: "You're funny" will return "You\'re funny" in my script.  I have a feeling this is a regex issue, but am not sure.  I tried looking through the PHP manual, but I'm not even sure what I'm looking at yet.  I'm only half way through the Zend tutorial.

 

Thanks in advance and sorry about the newbie question.

PHP file

<html>
<head>
<title></title>
</head>
<body>

<?php

$input = $_POST['yourname'];

echo $input."<br />";

?>

<?php

$input = $_POST['subject'];

echo $input."<br />";

?>

<?php

if (is_array($_POST['blah'])) {

echo "From the ";

foreach ($_POST['blah'] as $i) {

echo $i." department";

}

echo "<br />";

}

?>

<?php

$input = $_POST['msg'];

echo $input;

?>

</body>
</html>

 

HTML file

<html>
<head>
<title>K.C.'s Blog script</title>
</head>
<body>

<form action="blog.php" method="post">
Name: <select name="yourname">
<option value="K.C. Brawley">K.C. Brawley
<option value="Aaron Falanga">Aaron Falanga
</select> <br /><br />
Subject: <input type="text" name="subject" size="45"><br /><br />
<input type="radio" name="blah[]" value="General News">General News
<input type="radio" name="blah[]" value="Book Review">Book Review
<input type="radio" name="blah[]" value="Ranting and Raving">Ranting and Raving
<br /><br />

Message:<br />
<textarea cols="50" rows="4" name="msg"></textarea>
<br />
<input type="submit" name="submit" value="Submit Blog">
</form>

</body>
</html>

Should be as simple as applying stripslashes prior to output. eg;

 

<?php

echo stripslashes($input)."<br />";

?>

 

Geez, thanks man.  I was trying to take a crash course in regexes and everything, and it turns out it's as simple as this.. 

 

Again, thanks.

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.