highlight_string() not good enough

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

highlight_string() not good enough

Post 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. >.>
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 )
Post Reply