title: php escaping user input to display in html
body: <p>php page1 --> below bit is pure html:</p>
  
  <pre><code>&lt;form action="page2.php" method="post"&gt;
  &lt;input type="text" name="name" id="name"&gt;
  -----------submit button, end form --etc.--------------
  </code></pre>
  
  <p>php page2 (and yes i have intended to stuff the text input from page1 into a hidden input in page2):</p>
  
  <pre><code>foreach($_REQUEST as $key=&gt;$value) 
  {
       $value = htmlspecialchars(strip_tags(stripslashes($value))); //attempt to cleanse the data before displaying
  }
  echo "&lt;p&gt;&lt;input type='hidden' id='name' name='name' value='".$_REQUEST['name']."'/&gt;".$_REQUEST['name']."&lt;/p&gt;";
  </code></pre>
  
  <p>The problem is that the output on page 2 is not producing w3 compliant html if the user enters input with quotes such as John O'Brien, the html becomes:</p>
  
  <pre><code>&lt;p&gt;&lt;input type='hidden' id='email' name='email' value='John O'Brien'/&gt;John O'Brien&lt;/p&gt;
  </code></pre>
  
  <p>I would also like to be able to produce w3 compliant html for any bad input data such as: j'o/h\n s"m,ith</p>
  
  <p>Any help is appreciated! </p>