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" => "\\1",
"I" => "\\1",
"U" => "\\1",
"CENTER" => "
"URL" => "\\1",
"EMAIL" => "\\1",
"IMAGE" => "
\n",
"DOWNLOAD" => "exec:get_dl_html('\\1')",
"LIST" => "exec:get_list_html('\\1')",
"QUOTE" => "
引用: | |
|
"IFRAME" => "
"MOVE" => "
"GLOW" => "
\\1 |
"SHADOW" => "
\\1 |
"DROPSHADOW" => "
\\1 |
"GBMUSIC" => "
"MUSIC" => "
Download The Music |
"FLASH" => "
"SHOCKWAVE" => "
"QUICKTIME" => "
"REALPLAYER" => "
Download The Movie |
"MEDIAPLAYER" => "
Download The Movie |
"VOTE" => "exec:get_vote_html('\\1')",
);
$htc_list_att = array(
"ALIGN" => "
"URL" => "\\2",
"EMAIL" => "\\2",
"IMAGE" => "
\n",
"FONTFACE" => "\\2",
"FONTSIZE" => "\\2",
"FONTCOLOR" => "\\2",
"DOWNLOAD" => "exec:get_dl_html('\\1', '\\2')",
"LIST" => "exec:get_list_html('\\2','\\1')",
"ATTACH" => "exec:get_attach_html('\\2', '\\1')",
"VOTE" => "exec:get_vote_html('\\1','\\2')",
);
$htc_list_spl = array(
"PHP" => "exec:get_highlight_html('\\1', 'php')",
"CSS" => "exec:get_highlight_html('\\1', 'css')",
"HTML" => "exec:get_highlight_html('\\1', 'html')",
"SCRIPT" => "exec:get_highlight_html('\\1', 'script')",
"CODE" => "exec:get_code_html('\\1')",
"EXECUTE" => "\\1",
);
function get_highlight_html($str, $type = "php") {
$type = strtolower($type);
$type_func = $type."_highlight";
$type = strtoupper($type);
$result = "
高亮显示 {$type} 代码: | |
".($type=="HTML"?"":"")." |
";
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
\n":""), $arr_css[$i]);
$unit = preg_replace("/[\\\*\.\w#: ]+\{([^\{\}]+)\}/", "\\1", $arr_css[$i]);
$unit_list = preg_split("/;\s*/", $unit);
$unit = "\n";
for($j=0; $j
$unit .= " " . preg_replace("/\s*([\w\-]+)\s*:\s*(.*)/e", "'\\1 : '.htmlspecialchars('\\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("/(.*)/isU", "\\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("/(\.|\s)([a-z]+)\(/i" ,"\\1\\2(", $str);
$str = preg_replace("/\.(\w+)(?!\()/i" ,".\\1", $str);
$str = preg_replace("/\/\/([^\n]*)\n/e" ,"script_highlight_note('\\1', false)", $str);
$str = preg_replace("/\/\*(.*?)\*\//es" ,"script_highlight_note('\\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*('|\")([^'\"]+)\\1/eU","'=\\1'.preg_replace('/\s+/','|:s:|','\\2').'\\1'",$att);
$att = str_replace("\\\"","\"",$att);
$att .= " ";
preg_match_all("/[a-z:\/\-]+(=(['\"]?).*[^\\\\]{1}\\2?)?\s+/iU", $att, $att_list);
$att_list = $att_list[0];
for($i=0; $i
$att_list[$i] = trim($att_list[$i]);
$att_list[$i] = preg_replace("/([^=]+)([=]?)(['\"]?)(.*)(\\3)/", "\\1 font>\\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("/<script>]*)>(.*)<\/script>/isU", $str, $arr_tmp);<br> $arr_script = $arr_tmp[0];<br> for($i=0; $i<count($arr_script); $i++) {<br> $str = str_replace($arr_script[$i], "<br>::script_{$i}::<br>", $str);<br> $arr_script[$i] = preg_replace("/<script([^>]*)>(.*)<\/script>/iseU", "'<font color=\'{$color_2}\'><SCRIPT '.html_highlight_attr('\\1').'></script>
'.script_highlight(str_replace('\\\"','\"','\\2'), false).''", $arr_script[$i]);
}
$str = preg_replace("/(

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。