Greetings. I have a forum I have created and I want to be able to use Code tags (the same way this site does).
I figured I'd do it like this:
Find the position of the first [ PHP ] and the first [/ PHP]. Then, cut out all the text between that, and replace it with the higlighted version of that.
It worked ok, with the code I had (which I have since deleted), but then when testing with 3 or more sets of code, there were problems with replacing/cutting out the strings.
I had something like this: (Ignore the 's, they're there to stop vBulletin replacing the php code things).
$string = "[*php]<?php some code to echo?>[/*php]";
$start = strpos($string, "[*php]");
$end = strpos($string, "[/*php]");
$oldsegment = substr( $string , $start, $end);
$codesegment = highlight_string($oldsegment, true);
str_replace( $oldsegment, $codesegment, $string);
echo $string;
This seemed logical and worked fine when theres only one instance of [*PHP], but anymore and it seems to foul up.
Does anyone have any other ideas on ways I could do this? any help would be great 🙂
~ Paul