SyncViews Posted January 1, 2008 Share Posted January 1, 2008 How do I get php to add html tags to highlight code? Some of them (like == or <=) I can just do by replaceing say '==' with '<span class="comparison">==</span>' But what of strings, varibles, reals etc? eg if (height >= 125 || width >= 125) { tobig = 1; show_message('Item is to big'); } need to go to: <span class="conditional">if</span> (<span class="var">height</span> <span class="comparison"><=</span> <span class="real">125</span> <span class="logical">||</span> <span class="var">width</span> <span class="comparison">>=</span> <span class="real">125</span>) { <span class="var">tobig</span> <span class="assignment">=</span> <span class="real">1</span>; <span class="function">show_message</span>('<span class="string">Item is to big</span>'); } Link to comment https://forums.phpfreaks.com/topic/84025-syntax-high-lighting/ Share on other sites More sharing options...
trq Posted January 1, 2008 Share Posted January 1, 2008 Before you get a headache you might want to take a look at geshi or at the very least the highlight_string() function. Link to comment https://forums.phpfreaks.com/topic/84025-syntax-high-lighting/#findComment-427619 Share on other sites More sharing options...
SyncViews Posted January 2, 2008 Author Share Posted January 2, 2008 As I only really want something to prase one thing useing one style (useing existing css files) there must be a better way without all the bulk GeShi adds... Basicly I need it to do serval passes adding tags arcording to some basic rules eg (could merge some of these but it's easyer to understand this way I think) 1st pass: add comment tags to all "/* .... */" blocks 2nd pass: add comment tags from "//" to the end of the line while igornaing existing comment blocks 3rd pass onwards - skip all code within comment blocks: add string tage to all "..." and '...' blocks 4th pass onwards - skip all comments and string blocks: replace certain items (eg "if", "else", "=", "+") with versions includeing tags 5th pass: add real tags to all numbers 6th pass: add tags to all functions (mayby by detecting the string(...)?) 7th pass: add constant tags to all predefined constants (these constants could be stored in an array) 8th pass: All remaining strings outside tags are given varible tags Link to comment https://forums.phpfreaks.com/topic/84025-syntax-high-lighting/#findComment-427713 Share on other sites More sharing options...
SyncViews Posted January 5, 2008 Author Share Posted January 5, 2008 Still want to know how to do this... I really would rather write my own code than work with someone elses system that has lots of stuff I do not want. Link to comment https://forums.phpfreaks.com/topic/84025-syntax-high-lighting/#findComment-431429 Share on other sites More sharing options...
papaface Posted January 5, 2008 Share Posted January 5, 2008 Theres no point in reinventing the wheel by the way. Link to comment https://forums.phpfreaks.com/topic/84025-syntax-high-lighting/#findComment-431436 Share on other sites More sharing options...
SyncViews Posted January 6, 2008 Author Share Posted January 6, 2008 ok...but I still need a way to make geshi or whatever only handle text within the block (where xxx is php or htm or whatever) Link to comment https://forums.phpfreaks.com/topic/84025-syntax-high-lighting/#findComment-431764 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.