Jump to content

PHP Code Highlighting


adamwhiles

Recommended Posts

I was wondering how to go about highlight example php code. I have a page where I show examples of how to use php code and I would like to highlight the php code in it, alot like phpfreaks does on their tutorial pages. I already have a box with the code in it that displays fine, I just want to color the syntax and format it a little. A point in the right direction would be much appreciated. Thanks
Link to comment
https://forums.phpfreaks.com/topic/14812-php-code-highlighting/
Share on other sites

Well here is an example of what i have:

[code]
<div id="php_code_header">PHP Code Example:</div>
<div id="php_code">
if (IsSet($_POST['Submit'])) {
<br>echo "The submit button was pressed";
<br>}
<br>else {
<br>echo "The submit button was not pressed";
<br>}
</div>
[/code]

The div's setup my box the code is contained in, and I want the rest to be highlighted. I'm not sure I understand how to go about this.
Link to comment
https://forums.phpfreaks.com/topic/14812-php-code-highlighting/#findComment-59161
Share on other sites

Ok. 

I think there's a possibilty you are going about presenting the code the wrong way.  And by the way,  I love the avatar.  It sounds like you are either making a forum type system, or maybe just highlighting some could for tutorials.

Are you accepting a POSTed string and highlighting it, or are you purposely putting code inside a variable then printing it?

If you can tell me what and/or how your process works, I might be able to suggest a better situation for you.
Link to comment
https://forums.phpfreaks.com/topic/14812-php-code-highlighting/#findComment-59169
Share on other sites

I figured it out through a little trial and error. Thanks for you help though. Glad you like my avatar. Here is the code I used in case anyone else needs help with this.

[code]
highlight_string('<? if (IsSet($_POST[\'Submit\'])) {
echo "The submit button was pressed";
}
else {
echo "The submit button was not pressed";
}
?>');
[/code]
Link to comment
https://forums.phpfreaks.com/topic/14812-php-code-highlighting/#findComment-59172
Share on other sites

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.