Search code examples
javahighlightingsyntaxhighlighter

SyntaxHighlighter with php to load page?


I am attempting to use Alex Gorbatchevs Syntax Highlighter in conjunction with a variety of java examples. Instead of copying and pasting each example into its own html page, I would love to use php to get the filename and path, and then load the text content in between the "pre" tags... something like

<?php
echo "<pre>";
include ("$filename");
echo "</pre>";
?>

Obviously, since it is in between the "pre" tags, this renders like

include("$filename");

with pretty highlighting... =P

Is there anything that will work for me? Or am I stuck with copying and pasting?


Solution

  • Are you sure? I have reproduced the scenario and works fine for me:

    code.php

    <? echo "this is my code"; ?>
    

    syntax.php

    <?
    $filename = "code.php";
    
    echo "<pre>";
    include("$filename");
    echo "</pre>";
    ?>
    
    <script type="text/javascript">
         SyntaxHighlighter.all()
    </script>
    

    output:

    1  this is my code