Hi,

I am trying to make a code-highlighter which will pass through text which is posted from a form (My web management module). I basically want to have exactly the same system as used on this website. Add [ php] [ /php] tags, and you have highlighted syntax. Cannot get it to work however.

Have some trouble figuring this one out though:

$postedcode1 = $_POST[content];  // for now, quick and dirty retrieval

$match = array('#\[php\](.*?)\[\/php\]#se');             // match against the php tags
preg_match_all($match, $postedcode1, $matches);  // do the matching

$match1 = "<?".$matches[0]."?>";
$postedcode = highlight_string($match1, true);
echo "<hr>".$postedcode."<hr>";

This goives me the error: Warning: Delimiter must not be alphanumeric or backslash in ...
referring to the preg_match_all statement.

What do I need to change to get it to work?

Anybody with better ideas on how to run this? It is a bit cumbersome..

    The first argument to preg_match_all() must be a string and you're passing an array!

    Also, you don't need to backslash the forward slash since you're using #

    So, change this part of the expression:

    [\/php]

    to this:

    [/php]

    You might want to add the 'i' option along with your 'se' option so it will find the PHP tags case-insensitive.

    This can actually get very complicated quick. Remember, that people might use two sets (or more) of PHP tags, and what if they forget to use the closing tags, or nest them accidentally. Just things to watch out for.

    hth.

      Hi Toplay,

      That got me going again! THanks!

      I do realize all the valid points you made. Fortunately, it is for myself, and needs a little bit less fool-proofing:
      I was offered a job at RMIT in Melbourne, and am migrating there semi-permenantly, if I get all the paperwork done. So I have closed my web-design compagny, and am now transforming my website into a snippets portal, and online tutorial, which I would like to maintain at ease, using a nice interface, instead of the usual notepad thing.

      J.

        Write a Reply...