CodeIgniter Forums
Code highlighting - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Code highlighting (/showthread.php?tid=25447)



Code highlighting - El Forum - 12-12-2009

[eluser]Arun Joshi[/eluser]
Hi All

I would like to start my personal blog in codeigniter. There I have a lot of php code to display. So I want to highlight the php codes on each posts. I like the CI forum code highligthing very much. Is CI providing any libraries or methods for this?

Code:
function show()
{
echo "I like to highlight my code like this. ";

}

Thanks :-)


Code highlighting - El Forum - 12-12-2009

[eluser]Jamie Rumbelow[/eluser]
You sure can! It's in the Text Helper:

Code:
$this->load->helper('text');

highlight_code('Mmmm, some nice code to highlight');

Jamie


Code highlighting - El Forum - 12-12-2009

[eluser]überfuzz[/eluser]
There's always the core library: highlight_string


Code highlighting - El Forum - 12-24-2009

[eluser]Arun Joshi[/eluser]
How can we specify colors?


Code highlighting - El Forum - 12-24-2009

[eluser]rogierb[/eluser]
dude, did you read the userguide?

Quote:highlight_code()

Colorizes a string of code (PHP, HTML, etc.). Example:
$string = highlight_code($string);

The function uses PHP's highlight_string() function, so the colors used are the ones specified in your php.ini file.



Code highlighting - El Forum - 12-24-2009

[eluser]Phil Sturgeon[/eluser]
Here is a very decent library that acts for a wrapper to GeSHI.

http://shivercube.com/programming/php/codeigniter-code-highlighter-library/