Custom BBcode to pass to a script.
Posted: Sat Dec 11, 2004 12:37 pm
OK, I am allowing my users to submit articles to my site. This is a web developers site so of course their articles will sometimes need to contain code. I am using the GeSHi syntax highliter class so highlighting is not a problem. The problem is I want to allow my users to use BBcode just like SitePoint does for PHP code to pass the code to GeSHi for highlighting.
PLEASE NOTE: I already know about the PHP highlight function "for PHP Code". I need to use BBcode because the site will support many languages, Actionscript, Javascript, CSS, PHP, ASP, etc.
So for each language I want to have a BBcode for it like
[*ASP][*/ASP]
[*PHP][*/PHP]
[*CSS][*/CSS]
[*JS][*/JS]
(without the * of course)
So when a user submits a post, and the $postBody variable looks like say:
I need to send $postBody to a BBcode parser and grab everything inside [*PHP][*/PHP] to send to GeShi in the following format:
I only need those 2 things because I pass it to GeSHi like so:
^^ path is just the path to GeSHi
I can echo it back like this:
So the question is....
How do I grab the data already inside $postBody in the BBcode tags along with the tag identifier in those 2 variables... then... after I pass it to GeSHi, echo $postBody with the GeShI formatted code?
PLEASE NOTE: I already know about the PHP highlight function "for PHP Code". I need to use BBcode because the site will support many languages, Actionscript, Javascript, CSS, PHP, ASP, etc.
So for each language I want to have a BBcode for it like
[*ASP][*/ASP]
[*PHP][*/PHP]
[*CSS][*/CSS]
[*JS][*/JS]
(without the * of course)
So when a user submits a post, and the $postBody variable looks like say:
Code: Select all
$postBody = 'Some text describing the code.
Then some more text almost a paragraph worth.
OK here's an example:
[*PHP]$foo = 45;
for ( $i = 1; $i < $foo; $i++ )
{
echo "$foo<br />\n";
--$foo;
}[*/PHP]
Now more text yadda yadda.
Did you like my example,
yadda yadda yadda.';Code: Select all
$lang = 'PHP'; <-- I need it to recognize the tag name
$source = 'the code here'; <-- take only the code between the tagsCode: Select all
$geshi = new GeSHi($source, $lang, $path);I can echo it back like this:
Code: Select all
echo $geshi->parse_code();How do I grab the data already inside $postBody in the BBcode tags along with the tag identifier in those 2 variables... then... after I pass it to GeSHi, echo $postBody with the GeShI formatted code?