title: What is the correct/safest way to escape input in a forum?
body: <p>I am creating a forum software using php and mysql backend, and want to know what is the most secure way to escape user input for forum posts.</p>
  
  <p>I know about htmlentities() and strip_tags() and htmlspecialchars() and mysql_real_escape_string(), and even javascript's escape() but I don't know which to use and where.</p>
  
  <p>What would be the safest way to process these three different types of input (by process, I mean get, save in a database, and display):</p>
  
  <ol>
  <li>A title of a post (which will also be the basis of the URL permalink).</li>
  <li>The content of a forum post limited to basic text input.</li>
  <li>The content of a forum post which allows html.</li>
  </ol>
  
  <p>I would appreciate an answer that tells me how many of these escape functions I need to use in combination and why.
  Thanks!</p>