PHP-HtmlTransferCode_php基础
时间:2021-07-01 10:21:17
帮助过:11人阅读
PHP - Html Transfer Code
超文本转换码,市面上这东西已经很滥(多)了,不过是这几天自己实践了一下~~~~
支持 多重嵌套 和 同标签嵌套,混合高亮显示(还有一点小问题)
自我感觉便于修改和扩充~~~~~~~~~~~
/**************************************************
* *
* Name : Functions 4 Html Transfer Code (HTC) *
* Version : 1.3.2 *
* Author : Windy_sk *
* Create : 2003-09-03 *
* Modified: 2003-12-17 *
* Email : windy_sk@126.com *
* HomePage: None (Maybe Soon) *
* Notice : U Can Use & Modify it freely, *
* BUT PLEASE HOLD THIS ITEM. *
* *
**************************************************/
$htc_list = array(
"B" => "
\https://www.gxlcms.com/\1",
"I" => "
\https://www.gxlcms.com/\1",
"U" => "
\https://www.gxlcms.com/\1",
"CENTER" => "
\https://www.gxlcms.com/\1\n",
"URL" => "\https://www.gxlcms.com/\1",
"EMAIL" => "\https://www.gxlcms.com/\1",
"IMAGE" => "
\n",
"DOWNLOAD" => "exec:get_dl_html('\https://www.gxlcms.com/\1')",
"LIST" => "exec:get_list_html('\https://www.gxlcms.com/\1')",
"QUOTE" => "
引用: |
\https://www.gxlcms.com/\1 |
|
\n",
"IFRAME" => "
\n",
"MOVE" => "
\n",
"GLOW" => "\https://www.gxlcms.com/\1 |
\n",
"SHADOW" => "\https://www.gxlcms.com/\1 |
\n",
"DROPSHADOW" => "\https://www.gxlcms.com/\1 |
\n",
"GBMUSIC" => "\n",
"MUSIC" => "\n",
"FLASH" => "\n",
"SHOCKWAVE" => "\n",
"QUICKTIME" => "\n",
"REALPLAYER" => "\n",
"MEDIAPLAYER" => "\n",
"VOTE" => "exec:get_vote_html('\https://www.gxlcms.com/\1')",
);
$htc_list_att = array(
"ALIGN" => "\https://www.gxlcms.com/\2\n",
"URL" => "\https://www.gxlcms.com/\2",
"EMAIL" => "\https://www.gxlcms.com/\2",
"IMAGE" => "
\n",
"FONTFACE" => "\https://www.gxlcms.com/\2",
"FONTSIZE" => "\https://www.gxlcms.com/\2",
"FONTCOLOR" => "\https://www.gxlcms.com/\2",
"DOWNLOAD" => "exec:get_dl_html('\https://www.gxlcms.com/\1', '\https://www.gxlcms.com/\2')",
"LIST" => "exec:get_list_html('\https://www.gxlcms.com/\2','\https://www.gxlcms.com/\1')",
"ATTACH" => "exec:get_attach_html('\https://www.gxlcms.com/\2', '\https://www.gxlcms.com/\1')",
"VOTE" => "exec:get_vote_html('\https://www.gxlcms.com/\1','\https://www.gxlcms.com/\2')",
);
$htc_list_spl = array(
"PHP" => "exec:get_highlight_html('\https://www.gxlcms.com/\1', 'php')",
"CSS" => "exec:get_highlight_html('\https://www.gxlcms.com/\1', 'css')",
"HTML" => "exec:get_highlight_html('\https://www.gxlcms.com/\1', 'html')",
"SCRIPT" => "exec:get_highlight_html('\https://www.gxlcms.com/\1', 'script')",
"CODE" => "exec:get_code_html('\https://www.gxlcms.com/\1')",
"EXECUTE" => "\https://www.gxlcms.com/\1",
);
function get_highlight_html($str, $type = "php") {
$type = strtolower($type);
$type_func = $type."_highlight";
$type = strtoupper($type);
$result = "
";
return $result;
}
function php_highlight($str) {
$str = str_replace("\\\"","\"",$str);
return highlight_string($str, true);
}
function css_highlight($str, $nl = true) {
$color_1 = "red";
$color_2 = "green";
$color_3 = "blue";
$str = str_replace("\\\"","\"",$str);
$str = str_replace("\r", "", $str);
preg_match_all("/[\\\*\.\w#: ]+\{[^\{\}]+\}/", $str, $arr_css);
$arr_css = $arr_css[0];
for($i=0; $i $head = preg_replace("/([\\\*\.\w#: ]+\{)[^\{\}]+\}/", "\https://www.gxlcms.com/\1".($nl?"
\n":""), $arr_css[$i]);
$unit = preg_replace("/[\\\*\.\w#: ]+\{([^\{\}]+)\}/", "\https://www.gxlcms.com/\1", $arr_css[$i]);
$unit_list = preg_split("/;\s*/", $unit);
$unit = "\n";
for($j=0; $j if(strlen($unit_list[$j])>0)
$unit .= " " . preg_replace("/\s*([\w\-]+)\s*:\s*(.*)/e", "'\https://www.gxlcms.com/\1 : '.htmlspecialchars('\https://www.gxlcms.com/\2').' ; '", $unit_list[$j]) . ($nl?"
\n":"\n");
}
$arr_css[$i] = $head . $unit . "}";
}
return join(($nl?"\n
\n":"\n\n"), $arr_css);
}
function script_highlight_note($str, $mode = true) {
$color_note = "gray";
$str = str_replace("\\\"","\"",$str);
$str = preg_replace("/(.*)<\/font>/isU", "\https://www.gxlcms.com/\1", $str);
$str = $mode?"/*{$str}*/":"//{$str}";
return "{$str}";
}
function script_highlight($str, $nl = true) {
$color_1 = "red";
$color_2 = "blue";
$color_3 = "brown";
$color_4 = "green";
$str = str_replace("\\\"","\"",$str);
$str = htmlspecialchars($str);
$str = str_replace("=","&equal;",$str);
$str = str_replace("|","&vertical;",$str);
$keywords = array(
"{$color_1}" => array("null", "true", "false", "NaN"),
"{$color_2}" => array("var", "for", "if", "else", "switch", "case", "function", "loop", "continue", "break", "<", ">", "!&equal;", "&equal;&equal;", "&equal;", "&&", "&vertical;&vertical;"),
"{$color_3}" => array("window", "self", "this", "event", "document", "opener", "Navigator", "Math", "Array", "String", "Object", "Function", "Number"),
);
foreach($keywords as $key => $value) {
for($i=0; $i $str = preg_replace("/(\W)(".$value[$i].")(\W)/", "\https://www.gxlcms.com/\1\https://www.gxlcms.com/\2\\3", $str);
}
}
$str = preg_replace("/(\.|\s)([a-z]+)\(/i" ,"\https://www.gxlcms.com/\1\https://www.gxlcms.com/\2(", $str);
$str = preg_replace("/\.(\w+)(?!\()/i" ,".\https://www.gxlcms.com/\1", $str);
$str = preg_replace("/\/\/([^\n]*)\n/e" ,"script_highlight_note('\https://www.gxlcms.com/\1', false)", $str);
$str = preg_replace("/\/\*(.*?)\*\//es" ,"script_highlight_note('\https://www.gxlcms.com/\1')", $str);
$str = str_replace("\t", " ", $str);
$str = str_replace("&equal;","=",$str);
$str = str_replace("&vertical;","|",$str);
return $nl?nl2br($str):$str;
}
function html_highlight_attr($att) {
$color_1 = "red";
$color_2 = "brown";
$color_3 = "black";
$att = str_replace("\\\"","\"",$att);
$att = preg_replace("/=\s*('|\")([^'\"]+)\https://www.gxlcms.com/\1/eU","'=\https://www.gxlcms.com/\1'.preg_replace('/\s+/','|:s:|','\https://www.gxlcms.com/\2').'\https://www.gxlcms.com/\1'",$att);
$att = str_replace("\\\"","\"",$att);
$att .= " ";
preg_match_all("/[a-z:\/\-]+(=(['\"]?).*[^\\\\]{1}\https://www.gxlcms.com/\2?)?\s+/iU", $att, $att_list);
$att_list = $att_list[0];
for($i=0; $i if(empty($att_list[$i])) continue;
$att_list[$i] = trim($att_list[$i]);
$att_list[$i] = preg_replace("/([^=]+)([=]?)(['\"]?)(.*)(\\3)/", "\https://www.gxlcms.com/\1 font>\https://www.gxlcms.com/\2 font>\\3\\4 font>\\3", $att_list[$i]);
}
return str_replace("|:s:|", " ", join(" ", $att_list));
}
function html_highlight($str) {
$color_1 = "red";
$color_2 = "blue";
$color_3 = "gray";
$str = str_replace("\\\"","\"",$str);
preg_match_all("/'", $arr_script[$i]);
}
$str = preg_replace("/(