Combine FCK and GeSHi to make your PHP code syntax explicit

Source: Internet
Author: User
Tags php code

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 &copy; 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.