PDA

View Full Version : phpbb-tag


Mas*Mind
Fri 8th Dec '00, 6:29am
It would be cool if a [php] bbcode-tag will be added:


$bbcode=preg_replace("/(\[php])(.*)(\[\/php\])/siUe", "highlite('\\2')",$bbcode);

function highlite($text)
{ ob_start();
highlight_string(stripslashes($text));
$buffer = ob_get_contents();
ob_end_clean();

return nl2br($buffer);
}


This will highlite all php-code within the php-tags

Example:

http://gathering.tweakers.net/showtopic/71255

[Edited by Mas*Mind on 12-08-2000 at 06:35 AM]

Menno
Fri 8th Dec '00, 8:06am
yeah, such an add would be very nice. And the code should work for other languages as well (mostly anyway).

JamesUS
Fri 8th Dec '00, 12:15pm
Seeing as it is similar to the code tag, maybe the two could work togethor, eg [code lang=php]
Hopefully we could find some libraries somewhere for other langs (if there are any).

JohnM
Fri 8th Dec '00, 12:32pm
That's awesome... how can you get it to call a function with the results of the regexp? cooolll...

BTW, the demo seems to be down...

Wayne Luke
Fri 8th Dec '00, 1:56pm
I think this is a good idea as well. You could use "Syntax files" to add new languages if needed to your forum. This would require more than regular expressions though. The CODE tag would have to become intelligent.

Mike Sullivan
Fri 8th Dec '00, 1:57pm
John-
http://www.php.net/manual/ref.pcre.php
Particularly preg_replace and the modifiers. (/e)

Mike Sullivan
Fri 8th Dec '00, 2:00pm
Hmm.. one problem: PHP4 only. That alone might be enough to take it out (use a switch perhaps)

JohnM
Fri 8th Dec '00, 3:24pm
Cool, thanks :)

Mas*Mind
Fri 8th Dec '00, 4:22pm
JamesUS > The difference is, the syntax will now be color-highlighted. And it works for almost every language, even html will be hightlighted (to a certain limit)

Ed > PHP4 only? You mean the e modifier? Where did you read that?

Mike Sullivan
Fri 8th Dec '00, 4:58pm
No, the e's in PHP3 to my knowledge :) I meant every other function (almost).

All the output buffering and (the key), highlight_string are PHP4 specific.

Mas*Mind
Fri 8th Dec '00, 5:20pm
damn, you're right :(

But then, it would be a very cool addon to hack in :D

Mike Sullivan
Fri 8th Dec '00, 5:25pm
Well, you could detect the PHP version [someone said floor(phpversion()) will return 3 or 4 -- I haven't tried it]. If it's PHP4, use the PHP syntax highlighting, otherwise, translate -> [ code] and -> [ /code].

Still, would be one sweet add on :) I think I'll add it into vBo once that relaunch actually happens (we're all slacking it seems ;))

[Edited by Ed Sullivan on 12-08-2000 at 05:27 PM]

Mas*Mind
Sat 9th Dec '00, 12:02pm
Yes, that wouldn't be too difficult. There is another reason to use PCRE (preg_...) expressions instead of the POSIX (ereg_...) ones; The PCRE are known to be twice as fast as the POSIX ones

cybrcyfr
Thu 8th Aug '02, 2:01pm
Part of our forums will be dedicated to scripting and we would like to have syntax highlighting for a bunch of different languages like VBscript, JScript, Perl, Python, etc...

Is there an addon for this yet? If not, can someone give me a push in the right direction to create syntax highlighting templates? I don't mind writing them, I just don't know how to integrate/implement them.


-Tyler Lynch
Klient.com Staff

Wayne Luke
Thu 8th Aug '02, 5:54pm
Originally posted by cybrcyfr
Part of our forums will be dedicated to scripting and we would like to have syntax highlighting for a bunch of different languages like VBscript, JScript, Perl, Python, etc...

Is there an addon for this yet? If not, can someone give me a push in the right direction to create syntax highlighting templates? I don't mind writing them, I just don't know how to integrate/implement them.


-Tyler Lynch
Klient.com Staff

This is a standard feature of vBulletin 2.0... YOu have to realize that this thread is 18 months old.

Mike Sullivan
Thu 8th Aug '02, 6:28pm
Originally posted by wluke


This is a standard feature of vBulletin 2.0... YOu have to realize that this thread is 18 months old. He means for other than PHP, which there isn't without hacking. I believe John actually released a hack a long time ago that did VB code. You could adapt it for other languages I'm sure. Check vBulletin.org.

cybrcyfr
Thu 8th Aug '02, 6:35pm
Yep, I meant other languages. I see how you do it with the php language, quite simple php_highlight() or somehting like that.

I looked on vB.org and didn't see anything...

Thanks!

John
Fri 9th Aug '02, 6:16am
There is one for Visual Basic somewhere there, which shouldn't be too hard to adapt for others.

Wayne Luke
Fri 9th Aug '02, 9:10am
Do a search for visbas.php on vBulletin.org. If you can't find it, let me know, I have it.

cybrcyfr
Fri 9th Aug '02, 12:25pm
I found a VB library, now I will extend it for JScript, Python, Perl, and TCL.

I will post them somewhere when I get them done...


http://www.ultraedit.com/downloads/additional.html