Hi and I am expanding one of my websites which requires me to write a script which has a language syntax highlighter (the gml/gamemaker language). So to do that I am using mainly preg replace and str replace. I have been working hard at it for the last 29 hours but there is just three bugs (or preg replace functions) which is messing up the end result. I have attached to this post the code (as an attachment) since several phrases in my code kept on getting replaced with the bbcode <code> tag but with the [] brackets.
The 3 preg replaces which are sending me crazy are as follows:
$textb=preg_replace("/([^)])( |
| |\>| \>|
\>| \>)(.*)\((.*)?\)([^(])?()/is",'$1$2<font color=#c#o#l#o#r#2#>$3($4)</font>$5',$textb);
// one preg replace that works was taken out from this spot.
$textb=preg_replace("/(\'(.*)\')/is","<font color=#c#o#l#o#r#3#>'$2'</font>",$textb);
$textb=preg_replace("/(\'([^'])\')/is","'</font>$2<font color=#c#o#l#o#r#3#>'",$textb);
You will find that above code in the attachment file with its surrounding code but it is those lines of code that are messing up the final result (I believe). Currently the below text is replace by the html below that. But please replace the brackets <> with the brackets [].
This is a test line
<code>
function('value1','value2','value3');
functionb("value1","value2",value3);
functionb("value1","value2",value3);
globalvar variable;
</code>
This is more text
The above is preg/str replaced with the below currently.
This is a test line<br>
<font ><font color=#000080>color=#000000><br>
function(<font color=#800000>'value1'</font>,<font color=#800000>'value2'</font>,<font color=#800000>'value3'</font>);<br>
functionb(<font color=#800000>"value1"</font>,<font color=#800000>"value2",value3);<br>
functionb("value1"</font>,<font color=#800000>"value2"</font>,value3)</font>;<br>
<b>globalvar</b> variable;<br>
</font><br>
This is more text
As you can see in the above box, there are a few final result bugs all of which I believe come from the php code in the first code box I posted. Could anyone help me with programming the preg syntax as I have used up all my ideas and no-longer have a clue on what to do for this problem.
Note: If you want all the code just download the attachment to this post as the bbcode syntax got mixed up with my php code due to the function: <code> but with the [] brackets.