","", ""),'',$str);
$str=str_replace(array("
]+>)/si', $input, null, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
foreach ($content as $val) {
//匹配未闭合的自闭合标签 如
等
if (preg_match('/<(\w+)[^\/]*>/si', $val, $m) && in_array(strtolower($m[1]), $_single_tags) ) {
$result .= "\r\n" . $val;
}
//匹配标准书写的自闭合标签,直接返回,不入栈
else if (preg_match('/<(\w+)[^\/]*\/>/si', $val, $m)) {
$result .= $val;
}
//匹配开始标签,并入栈
else if (preg_match('/<(\w+)[^\/]*>/si', $val, $m)) {
$result .= "\r\n" . str_repeat("\t", count($stack)) . $val;
array_push($stack, $m[1]);
}
//匹配闭合标签,匹配前先判断当前闭合标签是栈顶标签的闭合,优先闭合栈顶标签
else if (preg_match('/<\/(\w+)[^\/]*>/si', $val, $m)) {
//出栈,多余的闭合标签直接舍弃
if (strtolower(end($stack)) == strtolower($m[1])) {
array_pop($stack);
$result .= $val;
}
} else {
$result .= $val;
}
}
//倒出所有栈内元素
while ($stack) {
$result .= "".array_pop($stack).">";
$result .= "\r\n";
}
return $result;
}
//生成拼音
function str2pinyin($str){
require_once('pinyin/ChinesePinyin.class.php');
$Pinyin=new ChinesePinyin();
$strPinyin = $Pinyin->TransformWithTone($str);
return $strPinyin;
}
function get_pinyinto($str){
//拼音分行 start
$str=str_replace(array("","
"),'',$str);
$str=str_replace(array("
","
","
","/P"),chr(13),$str);
$pyarr=explode(chr(13),$str);
//print_r($pyarr);
$pybody="";
//调用拼音程序
//str2pinyin()
require_once 'pinyin/ChinesePinyin.class.php';
//require_once (dirname(__FILE__) . "/ChinesePinyin.class.php");
$Pinyin=new ChinesePinyin();
foreach($pyarr as $k=> $v){
$pys = $Pinyin->TransformWithTone($v);
$pybody.=''.$pys.'';
$pybody.=''.$v.'
';
}
return $pybody;
}
//取汉字首字母
function getFirstCharter($str)
{
if (empty($str)) {
return '';
}
$fchar = ord($str{0});
if ($fchar >= ord('A') && $fchar <= ord('z'))
return strtoupper($str{0});
$s1 = iconv('UTF-8', 'gb2312', $str);
$s2 = iconv('gb2312', 'UTF-8', $s1);
$s = $s2 == $str ? $s1 : $str;
$asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
if ($asc >= -20319 && $asc <= -20284)
return 'A';
if ($asc >= -20283 && $asc <= -19776)
return 'B';
if ($asc >= -19775 && $asc <= -19219)
return 'C';
if ($asc >= -19218 && $asc <= -18711)
return 'D';
if ($asc >= -18710 && $asc <= -18527)
return 'E';
if ($asc >= -18526 && $asc <= -18240)
return 'F';
if ($asc >= -18239 && $asc <= -17923)
return 'G';
if ($asc >= -17922 && $asc <= -17418)
return 'H';
if ($asc >= -17417 && $asc <= -16475)
return 'J';
if ($asc >= -16474 && $asc <= -16213)
return 'K';
if ($asc >= -16212 && $asc <= -15641)
return 'L';
if ($asc >= -15640 && $asc <= -15166)
return 'M';
if ($asc >= -15165 && $asc <= -14923)
return 'N';
if ($asc >= -14922 && $asc <= -14915)
return 'O';
if ($asc >= -14914 && $asc <= -14631)
return 'P';
if ($asc >= -14630 && $asc <= -14150)
return 'Q';
if ($asc >= -14149 && $asc <= -14091)
return 'R';
if ($asc >= -14090 && $asc <= -13319)
return 'S';
if ($asc >= -13318 && $asc <= -12839)
return 'T';
if ($asc >= -12838 && $asc <= -12557)
return 'W';
if ($asc >= -12556 && $asc <= -11848)
return 'X';
if ($asc >= -11847 && $asc <= -11056)
return 'Y';
if ($asc >= -11055 && $asc <= -10247)
return 'Z';
return null;
}
?>