PHP - HTML 転送コード
ハイパーテキスト変換コード、すでにたくさん出回っていますが、最近は自分でも実践しています~~~~
複数のネストと同じラベルのネスト、混合ハイライトをサポートしています(もう1つの小さな問題)
I変更と拡張が簡単だと感じます~~~~~~~~~~
/**************************************************
* *
* 名前 : Functions 4 Html Transfer Code (HTC) *
* バージョン : 1.3.2 *
* 著者 : Windy_sk *
* 作成日: 2003-09-03 *
* 変更日: 2003-12-17 *
*メール : Windy_sk@126.com *
* ホームページ: なし (近いうちに) *
* 注意事項: 自由に使用および変更できます。このアイテムを持ってください。 *
* *
******************************************* *****/
$htc_list = array(
"\1< ;/b>",
"I" "I" => "\1",
"U" "U" => "\1 u> ",
"CENTER" "CENTER" => "
"URL" "URL" => " ",
「メール」 ;br /<表の配置=中央幅='100%'>
n",
"ダウンロード" "ダウンロード" => "exec:get_dl_html('\1')",
"リスト" => "exec:get_list_html('\1')",
"QUOTE" " 引用: < td> "IFRAME" => "
n",
"MOVE" => "
"GLOW" => "
n",\1
"SHADOW" => "
n",\1
"DROPSHADOW" => "
n",\1
"GBMUSIC" => "
"MUSIC" => "
n",
音楽をダウンロード
"フラッシュ" => "
n",
"SHOCKWAVE" => "
"クイックタイム" => "
n",
"REALPLAYER" => "
\n",
Download The Movie
"MEDIAPLAYER" => "
\n",
Download The Movie
"VOTE" => "exec:get_vote_html('\\1')",
);
$htc_list_att = array(
"ALIGN" => "
"URL" => "\2",
"メール” => a href='mailto:\1' >\2",
"画像" => "
n",
"FONTFACE" => "\2",
"FONTSIZE" => \2",
"FONTCOLOR" => "\2",
"ダウンロード" => dl_html(' \1', '\2')",
"リスト" => "exec:get_list_html('\2','\1')",
"ATTACH" => "exec:get_attach_html( '\2 ', '\1')",
"投票" => "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 = strto lower($type);
$type_func = $type."_highlight";
$type = strtoupper($type);
$result = "";
if(!function_exists($ type_func)) $type_func = "php_highlight";
$result .= "
高亮显示 {$type} 代:< ;/td>
".$type_func($ str)."
".($type=="HTML"?"gt;":"")."
";
$result;
}
関数php_highlight($ str) {
$str = str_replace("\"",""",$str);
return highlight_string($str, true);
}
function css_highlight($str, $nl = true) {
$color_1 = "赤";
$color_2 = "緑";
$color_3 = "青";
$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 : < font color='{$color_3}'>'.htmlspecialchars('\2').' ; $unit_list[$j]) 。 ($nl?"
n":"n");
}
$arr_css[$i] = $head 。 $単位 . "}";
}
return join(($nl?"n
n":"nn "), $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}";
}
FunctionScript_highlight($ str、$ nl = true){
$ color_1 = "red";
$ color_2 = "blue"; = 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", "関数", "数値"),
);
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< ;/font>", $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"; "",$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] =rim($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 = "ブルー";
$color_3 = "グレー";
$str = str_replace("\"",""",$str);
preg_match_all("//isU", $str, $arr_tmp);
$arr_script = $arr_tmp[0];
for($i=0; $i
::script_{$i}::
", $str);
$arr_script[$i] = preg_replace("//iseU", "'
'.script_highlight(str_replace('\"','"','\2'), false).''", $arr_script[$i]);
}
$str = preg_replace("/()/ieU" ,"'\1'.htmlspecialchars('\2').'\3'", $str);
$str = preg_replace("//seU" ,"''", $str);
$str = preg_replace("//isU" ,"\2", $str);
$str = preg_replace( "//ise" ,"' $str = preg_replace("/<(/[a-z:]+ )>/i" ,"<\1>", $str);
$str = preg_replace("/<(!- -.*--)>/sU" ,"<\1>", $str);
$str = preg_replace("/ ]*)>(.*)/iseU" ,"'
'.css_highlight(str_replace('\"','"','\2'), false).'
'", $str);
for($i=0; $i
::script_{$i}::
", $arr_script[$i], $str);
}
$str = str_replace(" font>", "
$str = str_replace(" b>", "", $str);
$str = str_replace(" >", " >", $str);
$str = str_replace(" "," ",$str);
$str = str_replace("t"," ",$str);
return nl2br($str);
}
function get_file_pic($filename) {
global $root_path;
$ext = str_replace(".","",strrchr($filename,"."));
$pic = $root_path."images/ mime_type/{$ext}.gif";
return file_exists($pic)?"$pic":$root_path."images/mime_type/attch.gif";
}
function get_dl_html($filename, $str = "") {
return " ".(empty($str)?basename($filename):$str)."";
}
function get_attach_html($filename, $ id) {
return " $filename";
}
function get_vote_html($vote_idx, $message = ""){
global $db_host, $db_user, $db_pass, $db_name;
$db = new DB_Manager($db_host, $db_user, $db_pass);
$db->Connect();
$db->SelectDB($db_name);
$ db->Query("select * from mnms_poll where id=".$vote_idx);
$record = $db->GetRS();
$str = "";
$db->close();
unset($db);
if($record) {
$username = "dummy";
$if_vote = !(strpos($record[vote_user], "|{$username}|")===false)
strpos($record[vote_user], "|".GetIp()."|");
$str .= "
<フィールドセット>