Powered by discuz! discuz!5 PHP code highlighting plugin (dancer update in the dark)

Source: Internet
Author: User
discuz!5.0 Forum display style PHP code highlighting plugin,
The PHP code syntax coloring, like the PHP comrades can easily see the code.
Also added HTML code to run the function.
This plugin was modified on the basis of a previous comrade's discuz!4 PHP code highlighting.
In addition, my PHP learning into a stagnant state,
I hope someone can help me out of PHP learning dilemma
My qq:5642382 QQ group: 2577162
function: Use [php]php code [/php] tag to highlight PHP code when posting,
Use the [runcode]html code [/runcode] tag to run the HTML code (run a non-server on the client).
Add the following steps to the plugin:
1. Modify Include/common.js
Find
function Copycode (obj) {
var rng = Document.body.createTextRange ();
Rng.movetoelementtext (obj);
Rng.scrollintoview ();
Rng.select ();
Rng.execcommand ("Copy");
Rng.collapse (FALSE);
}
Add the following at the end of this function:
[Copy to Clipboard] [ - ] CODE:
function RunCode (obj) {
var winname = window.open (', ' _blank ', ');
Winname.document.open (' text/html ', ' replace ');
Winname.document.writeln (Obj.value);
Winname.document.close ();
}
function Savecode (obj) {
var winname = window.open (', ' _blank ', ' top=10000 ');
Winname.document.open (' text/html ', ' replace ');
Winname.document.writeln (Obj.value);
Winname.document.execCommand (' SaveAs ', ' ', ' code.htm ');
Winname.close ();
}
2. Modify include/discuzcode.func.php
Find
[Copy to Clipboard] [ - ] CODE:
$discuzcodes [' Codecount ']++;
Return "[\tdiscuz_code_$discuzcodes[pcodecount]\t]";
}
(Note: You can also use EditPlus directly to find the 110th line of code to add the following)
Continue to add the following:
/-------Add [RunCode] HTML code [/runcode] to run HTML code
function Runcodedisp ($code) {
Global $discuzcodes;
$discuzcodes [' Pcodecount ']++;
$code = Htmlspecialchars (str_replace (' \ \ "', '" ', Preg_replace ("/^[\n\r]* (. +?) [\n\r]*$/is "," \\1 ", $code)));
$discuzcodes [' codehtml '] [$discuzcodes [' pcodecount ']] = "

<textarea name="\"runcode$discuzcodes[codecount]\"" rows="\"1\"" cols="\"95\"" style="\"height:200px\"">$code</textarea>

/g, "); Delpost.runcode$discuzcodes[codecount]. value = ffcod;Tip: You can modify some of the code before running
";
$discuzcodes [' Codecount ']++;
Return "[\tdiscuz_code_$discuzcodes[pcodecount]\t]";
}
-------Add [PHP] PHP code [/php] to highlight PHP code, PHP syntax coloring
function Phpcodedisp ($code) {
Global $discuzcodes;
$discuzcodes [' Pcodecount ']++;
$code = Phphighlite (Str_replace ("\\\", "\" ", $code));
$discuzcodes [' codehtml '] [$discuzcodes [' pcodecount ']] = "
The PHP code is as follows: $code
";
$discuzcodes [' Codecount ']++;
Return "[\tdiscuz_code_$discuzcodes[pcodecount]\t]";
}
function Phphighlite ($code) {
if (!strpos ($code, " $code = ' < '. Trim ($code). '? '. ' > ';
$addedtags = 1;
}
Ob_start ();
$oldlevel = error_reporting (0);
Highlight_string ($code);
Error_reporting ($oldlevel);
$buffer = Ob_get_contents ();
Ob_end_clean ();
if ($addedtags) {
$openingpos = Strpos ($buffer, ' $closingpos = Strrpos ($buffer, '? ');
$buffer = substr ($buffer, 0, $openingpos). substr ($buffer, $openingpos +5, $closingpos-($openingpos +5)). substr ($buffer , $closingpos +5);
}
$buffer = Str_replace (' "'," \ "", $buffer);
$buffer = Str_replace ('
', ', $buffer);
return $buffer;
}
-------End
3. Continue to modify include/discuzcode.func.php
Find
$message = Preg_replace ("/\s*\[code\" (. +?) \[\/code\]\s*/ies "," Codedisp (' \\1 ') ", $message);
Continue adding below it:
[Copy to Clipboard] [ - ] CODE:
-------RunCode
$message = Preg_replace ("/\s*\[runcode\" (. +?) \[\/runcode\]\s*/ies "," Runcodedisp (' \\1 ') ", $message);
-------PHP
$message = Preg_replace ("/\s*\[php\" (. +?) \[\/php\]\s*/ies "," Phpcodedisp (' \\1 ') ", $message);
[This post was last edited by yzxicq0 on 2006-9-4 17:11]

The above describes the powered by discuz! Discuz!5 's PHP code highlighting plugin (dancer update in the dark), including powered by discuz!, wants to help a friend who is interested in PHP tutorials.

  • 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.