Highlight PHP Source Code
The PHP language has two modes. It can either be used as a standalone language (pure mode) or it can be mixed with HTML (mixed mode) by putting it inside PHP tags (a form that resembles an XML processing instruction). This presents some challenges for the syntax highlighter.
If the code in the source block is pure PHP, you should use the language tag php
.
For example:
[source,php] ---- echo "Hello, World!"; ----
If the PHP source is mixed with HTML, you should either use the language tag html+php
, as shown here:
[source,html+php] ---- <p> <?php echo "Hello, World!"; ?> </p> ----
Or you should use the language tag php
and set the mixed
option on the source block, as shown here:
[source%mixed,php] ---- <p> <?php echo "Hello, World!"; ?> </p> ----
Under the covers, the syntax highlighter is configured to assume an implicit start PHP tag is present when the language tag is php
.
Both the mixed
option and the language tag html+php
disable this setting.