adamwhiles Posted July 17, 2006 Share Posted July 17, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/14812-php-code-highlighting/ Share on other sites More sharing options...
willfitch Posted July 17, 2006 Share Posted July 17, 2006 1. highlight a file = highlight_file('file.ext');2. highlight a string = highlight_string($string); Quote Link to comment https://forums.phpfreaks.com/topic/14812-php-code-highlighting/#findComment-59159 Share on other sites More sharing options...
adamwhiles Posted July 17, 2006 Author Share Posted July 17, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14812-php-code-highlighting/#findComment-59161 Share on other sites More sharing options...
willfitch Posted July 17, 2006 Share Posted July 17, 2006 I hope I understand what you're talking about.Try this:<div id="php_code_header">PHP Code Example:</div><div id="php_code"><?php highlight_string($code_to_highlight); ?></div> Quote Link to comment https://forums.phpfreaks.com/topic/14812-php-code-highlighting/#findComment-59165 Share on other sites More sharing options...
adamwhiles Posted July 17, 2006 Author Share Posted July 17, 2006 I would need to set something like this:$code = "echo \"Hello World!\";";highlight_string($code);I'm not sure how to properly keep the " in my code from causing problems, thats where I have trouble. Quote Link to comment https://forums.phpfreaks.com/topic/14812-php-code-highlighting/#findComment-59167 Share on other sites More sharing options...
willfitch Posted July 17, 2006 Share Posted July 17, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14812-php-code-highlighting/#findComment-59169 Share on other sites More sharing options...
adamwhiles Posted July 17, 2006 Author Share Posted July 17, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/14812-php-code-highlighting/#findComment-59172 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.