PHP not stripping slashes when echoing
<p>I'm hoping someone can clear this up for me. I have been reading a book on best practices when it comes to form validation and that if the user enter a wrong value return the form back to them with the data they entered with warning/error messages. </p>

<p>What I want to do is say a user enters the below into a text box: </p>

<pre><code>hello " there 
</code></pre>

<p>I want to return the above in the text box. Now when I use the below code it adds a slash. </p>

<pre><code>&lt;input name="name" id="name" type="text" class="formbox"
    &lt;?
        php if ($missing || $errors) {
            echo 'value="' . htmlentities($name) . '"';
        } 
    ?&gt;
&gt;
</code></pre>

<p>What I considered doing is this:</p>

<pre><code>&lt;input name="name" id="name" type="text" class="formbox"
    &lt;?
        php if ($missing || $errors) {
            $name = stripslashes($name);
            echo 'value="' . htmlentities($name) . '"';
        } 
    ?&gt;
&gt;
</code></pre>

<p>While the above works it seems inefficient. If I use just 'stripslashes' then anything after the " is removed. Currently the form is just checking its self in the sense that when the user clicks submit the form reloads and an IF statement catches any posts which then checks to see if there are any missing fields.</p>

<p>I hope this all makes sense as I have been unable to find a best solution on SO and Google.</p>

<p>Many thanks for any help in advance :) </p>
