How do you colour code the source in the answers on alt-php-faq.org?
By Arun Desai
hi,
How do you colour code the source in the answers on alt-php-faq.org
Teacher SiliconIndia replied to Arun Desai Friday, November 27, 2009
Hi arun,
We use a snippet of code that looks for
<code>
</code>
and colours anything in the middle as source, the source must contain opening and closing PHP tags i.e.
The script is as follows :-
<?
//$source contains the answer.
$nocode=0;
if(stristr($source,"<code>"))
{
$code=1;
do
{
list ($beginingtext,$code) = split ("<code>", $source,2);
list ($source,$endtext) = split ("</code>", $code,2);
echo nl2br($beginingtext);
highlight_string($source);
if(stristr($endtext,"<code>"))
{
$code=1;
$source=$endtext;
}else
{
$code=0;
}
}while($code==1);
echo nl2br($endtext);
echo "<P>";
}else
{
echo nl2br($source);
}
?>