proggR Posted July 9, 2008 Share Posted July 9, 2008 Does anybody know how the code tags work? How do they get parsed and formatted with the colors like they do? I want to include something to the same effect onto my website eventually but I'll also be using other languages so I'll likely need more than one parser. Anyway, if anyone knows it would be really helpful. <?php echo "How does it know?!"; ?> Quote Link to comment Share on other sites More sharing options...
Wolphie Posted July 9, 2008 Share Posted July 9, 2008 Basically, regular expressions are used to detect certain characters/tags in text and gets the value in between them. Depending on which tag is used, the HTML is appropriately formatted. This also helps prevent XSS, and Injections too, by not allowing the user to directly enter HTML tags. Quote Link to comment Share on other sites More sharing options...
proggR Posted July 9, 2008 Author Share Posted July 9, 2008 Oh I understand that part of it. I was just wondering how the code tags themself are formatted. I understand that bold tags with []would put bold tags with <> around the text and an image tag with [] would format it with the <>. But what tells the tags how to format variables and functions and strings the way that it does, wigh the different colors. I could easily format my code in the font thats used and in the box with a separate colored background. But how does it know to make "echo" green and the string red? Does it compare each and every word with a list? Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted July 9, 2008 Share Posted July 9, 2008 you can use the show_source function in php http://php.net/show_source Quote Link to comment Share on other sites More sharing options...
proggR Posted July 9, 2008 Author Share Posted July 9, 2008 Thanks much, thats exactly what I was looking for. Do you know if there is anything like that for other languages like Java or C that would format them in a similar way? I know I've seen them formatted so there must be something. And just as a Pee Ess: I must admit, I'm fairly new to PHP. Two months ago I hadn't even looked at it. Everyday that I work with it, though, I'm more and more impressed with the amount of options and accessibility. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted July 9, 2008 Share Posted July 9, 2008 Not that I know of, they must be an external library that can be used for this but the above is the functions I use. Quote Link to comment Share on other sites More sharing options...
trq Posted July 9, 2008 Share Posted July 9, 2008 Ive used Geshi in the past with great success. Quote Link to comment Share on other sites More sharing options...
proggR Posted July 9, 2008 Author Share Posted July 9, 2008 Thanks much to rajivgonsalves and thorpe. I'll probably wait to incorporate this but its good to know anyway. Quote Link to comment 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.