I've created a very basic BBCode parser for my webpage (see attached). In my class I created a way to use [NOPARSE]
...
[/NOPARSE] as I would use on these message boards. Anything within these tags is highlighted with highlight_string() however highlight_string will not work if not provided an opening <?php tag. I thought about substr to see if the "code" within the php tags starts with <?php and prepend it if not, then remove it afterward.
The problem with this approach is what if it doesn't start with php code and there is an opening <?php tag later? Now it doesn't highlight properly! On the other hand there may be an opening tag AFTER a closing tag meaning the beginning is php code and should have the opening tag prepended... WHOA there! Basically what I'm looking for is a way to handle this so that the code can be highlighted properly without always having an opening tag at the start.
For example, the following both highlight properly on these boards, but not with my code:
function myFunction($var) {
return $var;
}
<?php
function myFunction($var) {
return $var;
}
Any thoughts how I should do this?