title: Display Javascript/Html/PHP as text
body: <p>I am trying to display code on a webpage, just as text, for the user to view. The code snippet is obtained from a database, input using a form, and put in a div using PHP. Jquery is then used to replicate the html of that div in another element. The code from the database will never be executed; I am basically just making notes.</p>
  
  <p>Code example: <code>alert('Hello')</code>; (could be PHP or html)</p>
  
  <p>What is the best way of displaying this as text, in my browser?</p>
  
  <ol>
  <li>Filter it somehow using PHP as it is input using a form.</li>
  <li>Use of HTML tags (pre, xmp tags, CDDATA).</li>
  <li>Convert special characters with some javascript function.</li>
  <li>combination of the above.</li>
  </ol>
  
  <p>Example of use below.</p>
  
  <p>PHP</p>
  
  <pre><code>$inputQuery="SELECT x FROM y";  
  $input = mysqli_query($dbc,$inputQuery);
  $row = mysqli_fetch_array($input);
  //no issues above, just used to clarify the issue. If $input is javascript code, the  below doesn't work.
  
  echo'
  &lt;div id="inputCode"&gt;'.$row["x"].'&lt;/div&gt;';
  </code></pre>
  
  <p>JAVASCRIPT/JQUERY</p>
  
  <pre><code>var inputCode = $("#inputCode").html();
  $( "#displayInputCode").html(inputCode);
  </code></pre>