highlight_string parsing in an article

From: Date: Sat, 17 Mar 2001 02:58:07 +0000
Subject: highlight_string parsing in an article
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-44340@lists.php.net to get a copy of this message
Okay, I have a bugger here. I am working on a script for my site to parse articles, comments, so that people use a special markup (like [b] [/b] for <b> </b>, etc). One of the feature I want to implement is a [code] feature that will parse the code between [code] and [/code] like it would in hightlight_string(). The problem is, I want this for all the code that could possible be represented in a comment or an article. In some of the articles I write, I have several examples of the code, and I would like each instance put through the above process, but not the entire article. So, I have hit a snag. First, highlight_string actually prints out the results, so as far as I know, it doesn't return anything (http://www.php.net/manual/en/function.highlight-string.php) except for a true/false result. What I want to have happen is parse the document, and take the stuff between the [code] tags, and parse that out. Of course, the entire article is being put through, so I imagine I will have to be using regular expressions or explode(), though I expect more the former. For example, take this: ------------- A quick overview of echo, and how and why you should try and use inline HTML instead of outputting with echo. Just something real quick and easy that I think is rather important. A quick overview of echo, and how it compares to coding your HTML as Inline. Test results have shown that inline display is 2 times faster than echo. echo - 0.063347 secs inline - 0.035276 secs For example: [code] <?phpif ($yes != "yes"){ echo "Yes is not Yes";}?> [/code] If you compare that to this: [code] <?phpif ($yes != "yes"){ ?>Yes is not Yes <?php}?> [/code] While this may not be immediately noticeable in small programs, if the program is large, or it starts to recieve a lot of hits, than you will appreciate the little extra speed that inline prints give you. Sure, it requires a bit of extra work on your part, but it does make for nicer programming. Also, if you think about it, its much easier to use inline than echo'ing everything you do. No more escaping the " in the HTML in the echo's. And you should use the " even if you plan on using echo, as its good form. --------------- Now, that would be in the database. When the article is veiwed, it is sent through a parser. The parser will pick up the code tags, and parse what is in between through highlight_string(). Unfortunately, like I said, I cannot figure out how to do this, maintaining the structure of the article, while keeping it in one area. I don't want to create a seperate table to hold the code, and have that inserted into the articles as need parsed, just doesn't seem efficient enough. Any help would be appreciated. If you could point me to even a script that does something like this, I could hack my way through it, but I have don't know where to start with this. Thanks. Jason Lotito jason@lehighweb.com

« previous php.general (#44340) next »