GeSHi is a powerful language color-rendering plug-in that allows you to display language colors in the PHP code section of your article
First, the simplest way to do this is to call the main file first geshi.php
$geshi = new GeSHi($con, 'php');//文章内容,PHP代码
//行标
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5);
//灰背景
$geshi->set_overall_style('color: #000066;
border: 1px solid #d0d0d0; background-color: #f0f0f0;', true);
//标题
$geshi->set_header_content('lzy © 2008, View php source');
$geshi->set_header_content_style('font-family: Verdana, Arial, sans-serif;
color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff;
border-bottom: 1px solid #d0d0d0; padding: 2px;');
$geshi->set_footer_content('Parsed in seconds');
$geshi->set_footer_content_style('font-family: Verdana, Arial, sans-serif;
color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff;
border-top: 1px solid #d0d0d0; padding: 2px;');
$con = $geshi->parse_code();
So you can see that your code has a syntax color. And the function also adds a link that can directly access the use of the function
But now a lot of CMS Admin has adopted a variety of editors instead of a direct text field, in order to be able to use this online editor to do a good job of this function
We can do this: add the article can not do processing normal add, when you need to use the plug-in with [code] [/code] to make a mark
The key processing is the page displayed in the article:
1, first get the article has [code]
Preg_replace_callback ("/[Code]" (. +?) [/code]/s, ' geshi_content ', $content);
2. Perform color rendering
function Geshi_content ($con) {
$con = Str_replace ("& nbsp;", "", $con);
$con = Str_replace ("& amp;", "&", $con);
$con = Str_replace ("& gt;", ">", $con);
$con = Str_replace ("& lt;", "<", $con);
$con = Str_replace ("& quot;", "'", $con);
$con = Strip_tags ($con);
$geshi = new GeSHi ($con, ' php ');//article Content, PHP code
Row Mark
$geshi->enable_line_numbers (Geshi_fancy_line_numbers, 5);
Gray background
$geshi->set_overall_style (' Color: #000066;
border:1px solid #d0d0d0; Background-color: #f0f0f0; ', true ';
Title
$geshi->set_header_content (' Lzy © 2008, View PHP source ');
$geshi->set_header_content_style (' Font-family:verdana, Arial, Sans-serif;
Color: #808080; font-size:70%; Font-weight:bold; Background-color: #f0f0ff;
border-bottom:1px solid #d0d0d0; padding:2px; ');
$geshi->set_footer_content (' parsed in seconds ');
$geshi->set_footer_content_style (' Font-family:verdana, Arial, Sans-serif;
Color: #808080; font-size:70%; Font-weight:bold; Background-color: #f0f0ff;
border-top:1px solid #d0d0d0; padding:2px; ');
$con = $geshi->parse_code ();
return $con;
}
In this way we do not need to do any processing in the Add link, only to the article display page plus the above processing can let our article in the PHP code display color