php htmlspecialchars() from one form to another <p>Why can't htmlspecialchars() continually encode characters after each form submission? Take a look at the following example:</p> <pre><code>&lt;?php $_POST['txt'] = htmlspecialchars($_POST['txt']); ?&gt; &lt;form method="post"&gt; &lt;input name="txt" value="&lt;?=$_POST['txt'] ?&gt;" /&gt; &lt;input type="submit" name="save" value="test" /&gt; &lt;/form&gt; </code></pre> <p>You can see it at running at <a href="http://verticalcms.com/htmlspecialchars.php" rel="nofollow noreferrer">http://verticalcms.com/htmlspecialchars.php</a>.</p> <p>Now do the following</p> <pre><code>1) Type &amp; into the text field 2) Hit the test button once 3) When the page completes post back, hit the test button again 4) When the page completes post back, view the page source code </code></pre> <p>In the input box, the value is &amp; amp; </p> <p>I was expecting &amp; amp; amp;</p> <p>Why is it not &amp; amp; amp; ???</p>