I am trying to build a Javascript highlighter using PHP for my website, so when user posts <script> something </script> the "something" should get send to my highlighter and somehow combined back into the string and then displayed.
Heres what i have so far, i tried using eregi, but what happened was it would only do it at the first <script></script> ... if there is another <script></script> in the user input it would bug out.
So now im trying to use explode, and im not very good at array sorting, so how would i break the tags apart, then highlight inbetween tags, and then recombine it as a single string? Does anyone have a better function for it? Heres mine:
<?php
// Whats suppose to happen is every thing should be split and all the things inside <script></script>
// should be highlighted.
$dataread = "1 <script> 2 </script> 3 <script> 4 </script> 5";
$exp = explode("</script>", $dataread); // 1 <script> 2 3 <script> 4 5
for($i = 0; $i < count($exp); $i++){
$exp2 = explode("<script>", $exp[$i]);
$num = $i + 1;
$parse->set_lang('javascript');
$parse->setcode($exp2[$i]);
echo $parse->parse();
echo $exp2[$i+2]; // don't know how to recombine.
}
?>
Thats all i got so far. And it obviously won't work, so i am out of ideas.
Any help is appreciated thx.