1

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?

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

You are correct sir. The problem was the fact that I am a moron and was expecting the php scripts to work correctly when I viewed them in a browser like an html page. I uploaded the pages to a webhost, and this works perfectly. Thank you!
1

Don't use the include() method to do this - rather have a read / play with php's "fopen" command. http://php.net/manual/en/function.fopen.php

2 Comments

The issue is not that I can't import the text, it's the fact that any command contained between the <pre> tags is not executed...
I thought that was the point of a syntax highlighter, so that you can see code, and not execute it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.