I'm tryin to add a php highlighting code to my comment board

This is the replace:

    $msg = preg_replace("/([code=php])(.+)([\/php])/",highlight_code("//2"),$msg);

This is the highlight function:

function highlight_code($text)
{
  ob_start();
  highlight_string($text);
  $newtext = ob_get_contents();
  ob_end_clean();
  return $newtext;
}

I'm getting an error at the preg_replace so I'm guessing it doesnt like the function in the replace or something what should I do?

    Try this:

    preg_match_all("/(php)(.+)(/php)/",$msg,$tab,PREG_PATTERN_ORDER);

    $msg = highlight_code($tab[2][0]);

    $tab[2][0] is the content of the second () in the regular expression.

    $tab[1][0] would be the content of the second () in the regular expression.

    $tab[0][0] would be the first string matching the regular expression.

      nope but i kno the error is in the regular expression not the preg_replace now

        Maybe [,] and / must be escaped by a backslash

        Like

        $msg = preg_replace("/([php])(.+)([\/php])/",highlight_code("//2"),$msg);

          still nothing i dont kno whats wrong ;\

            $text = preg_replace("/[php](.*?)[\/php]/i",//1,$msg);
            highlight_string($text);

              blah nothings working i dont get it ;\

              i use these for bold underline an italics an they work fine

              $msg = preg_replace("/(\\[[B|b]\])(.+)(\\[\\/[B|b]\\])/","<b>\\\\2</b>",$msg);
              $msg = preg_replace("/(\\[[I|i]\\])(.+)(\\[\\/[I|i]\\])/","<i>\\\\2</i>",$msg);
              $msg = preg_replace("/(\\[[U|u]\\])(.+)(\\[\\/[U|u]\\])/","<u>\\\\2</u>",$msg);
              

                I am not sure whether it is valid to call a function within preg_replace. HTML tag is fine coz it doesnt need any kind of execution like php function does.

                  i dont think its the function cause ive tried using regular html tags around it an it still not do anything

                    Write a Reply...