Page 1 of 1

highlight_string() not good enough

Posted: Sun May 08, 2005 9:10 pm
by Skara
I figure this's been asked before, but I can't find it via searching.

If you don't have the <?php and ?> in the string to highlight, it doesn't do anything.
I'm working on making a

Code: Select all

code for my forums, but I figured it'd be easier if there were already a function...  Plus, these forums number the lines too.  Which I can't seem to figure out, as highlight_string() gets rid of \n, so there's no way to know where the line numbers are. ^^;

So anyway, would someone mind posting the function for these forums or a similar one?
I've tried using GeSHi, btw.  Takes too long to load, though. >.>

Posted: Mon May 09, 2005 2:15 am
by Chris Corbyn
A bit of regex sorts the <? ?> issue out (check that the tags are there... if the aren't then you need to add them but make sure you take them back out of the highlighted code.

You'll find that the

Code: Select all

tags on this forum actually just manipulate the highlight_string() output 

It just take some regex work to get it going.

If your only issues are line numbers and tags then you shouldn't have too much trouble 

I may have some code I can dig up actually which adds the tags if they aren't there (in my unorganised mess of server directories )