BBLOG PHP Syntax Highlighting Tutorial
March 30, 2005
I'll quickly describe how to get PHP Syntax highlighting using BBCode in your BBLOG application using GESHI (you can apply this same technique to any application). What we're going to do is enable our blog to support [ php] tags
Step 1.
Download Geshi from http://sourceforge.net/project/showfiles.php?group_id=114997
Step 2.
Unzip the files to your webdirectory that your blog is in. For example mine is located in litfuel.net/plush/bblog/bBlog_plugins/geshi/
Step 3.
open up the file modifier.bbcode.php script in bblog/bBlog_plugins/ folder. At the top of this file add the following
Step 4.
Add this block of code RIGHT BEFORE THE RETURN statement in the smarty_modifier_bbcode function. So locate
thats it! now when you write in your blog whenever you want to use PHP Syntax Highlighting just put [ php ] my php stuff [/ php ] tags in and use the BBCode Entry Modifier :)
There are tons of advanced features you could add with geshi but I tried to keep it super simple for the moment.
Step 1.
Download Geshi from http://sourceforge.net/project/showfiles.php?group_id=114997
Step 2.
Unzip the files to your webdirectory that your blog is in. For example mine is located in litfuel.net/plush/bblog/bBlog_plugins/geshi/
Step 3.
open up the file modifier.bbcode.php script in bblog/bBlog_plugins/ folder. At the top of this file add the following
// this is the path to the geshi.php file yours will obviously be different so change this! $include_path = "/plush/bblog/bBlog_plugins/geshi/"; // include main geshi file include_once($include_path."geshi.php");
Step 4.
Add this block of code RIGHT BEFORE THE RETURN statement in the smarty_modifier_bbcode function. So locate
and add the code below right above it.
/*------------------------------------------------------------------------------------------*/ // Jim Plush Add on for PHP Syntax Highlighting questions? <a href="mailto:jiminoc@gmail.com">jiminoc@gmail.com</a> // CHECK FOR PHP TAGS $regex = '/\[php\](.*?)\[\/php\]/si'; // GRAB THE PHP CODE WE WANT TO HIGHLIGHT IN $matches[1] // set path to the geshi FILES folder - notice I have the double geshi now this is where the php.php file is located $path = "/litfuel.net/plush/bblog/bBlog_plugins/geshi/geshi/"; // now we have to loop through all our matches because we can have multiple php brackets in our post for($i=0; $i < $cnt; $i++) { // Create a GeSHi object where php is the language we want to use $geshi = new GeSHi($matches[1][$i], 'php', $path); // lets enable line numbers so people can comment based on the line $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); $phpcode = $geshi->parse_code(); } /*------------------------------------------------------------------------------------------*/
thats it! now when you write in your blog whenever you want to use PHP Syntax Highlighting just put [ php ] my php stuff [/ php ] tags in and use the BBCode Entry Modifier :)
There are tons of advanced features you could add with geshi but I tried to keep it super simple for the moment.
Anonymous says:
May 12, 2005 @ 19:42 — Reply
Cool. Have to check it out.
johno says:
June 2, 2005 @ 14:47 — Reply
Have you tried fshl? FSHL? Supports multi-syntax highlighting, generates output really fast and has really nice stylesheet ;)
slavka says:
July 22, 2005 @ 00:31 — Reply
I think the following works fine too.... all other steps keep the same apart from the php code parsing try the one below :) //************************************************************************** // php syntax... //************************************************************************** $regex = '/\[php\](.*?)\[\/php\]/si'; preg_match_all($regex, $ret, $matches); $path = "c:/apachefriends/xampp/htdocs/bblog/bblog/bBlog_plugins/geshi/geshi"; $cnt = count($matches[1]); for($i=0; $i $content .= $matches[1][$i]; if ($i == ($cnt-1)) { $replacethis = $matches[0][$i]; } else { $ret = str_replace($matches[0][$i], $i , $ret); } } $geshi = new GeSHi($content, 'PHP', $path); $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); $geshi->set_url_for_keyword_group('php', 'http://www.php.net/{FNAME}'); $phpcode = ''.$geshi->parse_code().''; $ret = str_replace($replacethis, $phpcode , $ret); //echo $phpcode; //**************************************************************************
Anonymous says:
July 22, 2005 @ 00:32 — Reply
[php] //************************************************************************** // php syntax... //************************************************************************** $regex = '/\[php\](.*?)\[\/php\]/si'; preg_match_all($regex, $ret, $matches); $path = "c:/apachefriends/xampp/htdocs/bblog/bblog/bBlog_plugins/geshi/geshi"; $cnt = count($matches[1]); for($i=0; $i $content .= $matches[1][$i]; if ($i == ($cnt-1)) { $replacethis = $matches[0][$i]; } else { $ret = str_replace($matches[0][$i], $i , $ret); } } $geshi = new GeSHi($content, 'PHP', $path); $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); $geshi->set_url_for_keyword_group('php', 'http://www.php.net/{FNAME}'); $phpcode = ''.$geshi->parse_code().''; $ret = str_replace($replacethis, $phpcode , $ret); //echo $phpcode; //************************************************************************** [/php] :)
Anonymous says:
July 22, 2005 @ 00:33 — Reply
<?php echo "hello world";function &_loadElement($event, $type, $args) { $type = strtolower($type); if (!HTML_QuickForm::isTypeRegistered($type)) { return PEAR::raiseError(null, QUICKFORM_UNREGISTERED_ELEMENT, null, E_USER_WARNING, "Element '$type' does not exist in HTML_QuickForm::_loadElement()", 'HTML_QuickForm_Error', true); } $className = $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'][$type][1]; $includeFile = $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'][$type][0]; include_once($includeFile); $elementObject =& new $className(); for ($i = 0; $i < 5; $i++) { if (!isset($args[$i])) { $args[$i] = null; } } $err = $elementObject->onQuickFormEvent($event, $args, $this); if ($err !== true) { return $err; } return $elementObject; } // end func _loadElement?>
Anonymous says:
July 22, 2005 @ 00:33 — Reply
sorry for the multiple posts... but wish there was a php code allowance here :)
Xenom says:
April 27, 2006 @ 14:23 — Reply
Has been a while ago you posted this. I was looking for something like this for weeks, about an hour ago i found GeSHI, but unfortunatly no 'BB' code support like [ php] [ /php]. This fixes it all :) Many thanks!
Bert says:
August 4, 2007 @ 10:44 — Reply
There is no modifier.bbcode.php file included in the zip. I had to read the geshi-doc.txt file ("2.3: Basic Usage" section) to get it to work. Great script!
Louis Vuitton Handbags Replica says:
January 31, 2010 @ 20:34 — Reply
Comment pending moderation
ipod to mac says:
March 18, 2010 @ 06:36 — Reply
Comment pending moderation
ipod to mac says:
March 18, 2010 @ 06:38 — Reply
Comment pending moderation
room dividers nyc says:
March 18, 2010 @ 06:41 — Reply
Comment pending moderation
Anti Premature Ejaculation says:
March 29, 2010 @ 05:17 — Reply
Comment pending moderation
blu ray ripper says:
April 18, 2010 @ 04:35 — Reply
Comment pending moderation
AGPtek battery says:
May 6, 2010 @ 21:35 — Reply
Comment pending moderation
werjwerkw says:
May 10, 2010 @ 15:32 — Reply
Comment pending moderation
HP0-J33 says:
May 19, 2010 @ 00:25 — Reply
Comment pending moderation
online forex trading says:
May 21, 2010 @ 20:58 — Reply
Comment pending moderation
virbram five fingers says:
June 4, 2010 @ 21:02 — Reply
Comment pending moderation
traiteur hallal says:
June 11, 2010 @ 17:08 — Reply
Comment pending moderation
E20-322 says:
June 12, 2010 @ 17:57 — Reply
Comment pending moderation
watches replica says:
June 19, 2010 @ 00:44 — Reply
Comment pending moderation
Brand Lee says:
June 23, 2010 @ 02:00 — Reply
Comment pending moderation
chanel says:
June 23, 2010 @ 02:02 — Reply
Comment pending moderation
louis vuitton replica says:
June 24, 2010 @ 01:53 — Reply
Comment pending moderation
last longer in bed says:
June 24, 2010 @ 14:35 — Reply
Comment pending moderation