Jump to content

code highlighting on page?


renfley

Recommended Posts

i figured you send me to that LOL maybe i should re ask LOL

<?php

$codeToHighlight = "

<?php

echo 'This is a simple Echo Statment';

?>";

highlight_string($codeToHighlight);

?>

This will work fine but when i replace ' with " i get a bunch of errors? i was more or less looking for an alternative?

Solution !!!!!!!!!!

 

in order to get everything included in the highlight field without worrying about hacks you can simply do the following

 

Save the following as a regular text file in my case

dbconnect.txt

 

<?php

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');

if (!$link) {

    die('Could not connect: ' . mysql_error());

}

echo 'Connected successfully';

mysql_close($link);

?>

 

Then insert this little code

<?php

highlight_file("code/dbconnect.txt");

?>

And voila no need to worry about modifying your code for it to look the right way!

 

 

Putting it into the file seems to be the wise choice.

 

If, however, you plan on just displaying that file highlighted, you should be able to rename it to .phps (you may have to modify the apache httpd.conf and add the type) and it should show the source highlighted just fine.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.