Reputation: 3313
I get some html output as:
<div class="test-code">
<pre>
<code>
<?php echo "hello world"; ?>
</code>
</pre>
</div>
Is it possible to use any basic PHP syntax highlighter with above HTML without changing anything in above syntax? I have been searching, but most of the syntax highlighters seems to be pretty advanced and require to define the code class in the pre
(eg. pre class="php"
).
Edit: I am looking for any Javascript/jQuery based syntax highlight which automatically assumes that any code inside the <code>
is a PHP code and highlights it.
Upvotes: 0
Views: 485
Reputation: 2751
I would certainly recommend prettify.
It normally auto-detects the language being written in the code block.
Common usage is as follows:
<pre class="prettyprint">
<code>
// your code here
</code>
</pre>
NOTE: Prettify takes tabs literally. Do not tab your code within the block, but rather use spaces.
Upvotes: 1
Reputation: 32145
There's highlight_string()
but that really only highlights the PHP code and wraps everything else in <code>
tags
<?php
$markup = <<<MARKUP
<div class="test-code">
<pre>
<code>
<?php echo "hello world"; ?>
</code>
</pre>
</div>
MARKUP;
highlight_string($markup);
Output: http://codepad.org/qnLGqP7N
As far as I know, the method you mentioned is used by javascript highlighters.
Upvotes: 2