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?

Link to comment
Share on other sites

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!

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.