Jump to content

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

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.