Now: Tutorial for Web and Software Design > PHP > QA > PHP Content
> PHPFAQ - How do you colour code the source in the answers on alt-php-faq.org? [Bookmark it]
PHPFAQ - How do you colour code the source in the answers on alt-php-faq.org?


Question :

How do you colour code the source in the answers on alt-php-faq.org?

Answer :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);
}
?>



[Bookmark][Print] [Close][To Top]
  • Prev Article-PHP:

  • Next Article-PHP:
  • Related Materias
    PHPFAQ - How google is you
    PHPFAQ - Are there any web
    PHPFAQ - How can I accept 
    PHPFAQ - How can I finance
    PHPFAQ - Where can I get P
    PHPFAQ - Where can I host 
    PHPFAQ - Where can I find 
    PHPFAQ - I am trying to cr
    PHPFAQ - Is there a librar
    PHPFAQ - How can I manage 
    Topics
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Graphic Design Tutorial
     

    Coreldraw Tutorial

      Illustrator Tutorial
      3D Graphics Articles
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial&Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial&Articles
     

    XML Style Tutorial

      AJAX Tutorial
      XML Mobile
    Flash Tutorial&Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial&Articles
     

    Linux Tutorial

      Symbian Tutorial
      MacOS Tutorial