Search code examples
htmlpre

HTML - Display PHP code with <?php and ?>


I am writing a blog and when I display code, I usually do so like this:

< pre > < code > Code Goes Here < / code > < / pre>

But it will not display the starting of php <?php or the end ?> and I really need it to. Any suggestions?

Thanks.


Solution

  • To display special characters in HTML, you must escape them.

    < - &lt;
    > - &gt;
    & - &amp;
    " - &quot;
    ' - &#039;
    

    So in your case, you want

    <pre><code>&lt;?php (PHP CODE HERE) ?&gt;</code></pre>
    

    (Also notice the order of closing tags must match the order of opening tags.