$sublen) return join('', array_slice($t_string[0], $start, $sublen)).$after; return join('', array_slice($t_string[0], $start, $sublen)); } else { $start = $start*2; $sublen = $sublen*2; $strlen = strlen($string); $tmpstr = ''; for($i=0; $i<$strlen; $i++) { if($i>=$start && $i<($start+$sublen)) { if(ord(substr($string, $i, 1))>129) { $tmpstr.= substr($string, $i, 2); } else { $tmpstr.= substr($string, $i, 1); } } if(ord(substr($string, $i, 1))>129) $i++; } if(strlen($tmpstr)<$strlen ) $tmpstr.= $after; return $tmpstr; } } //HTML转txt function html2txt($html){ $html=strip_tags($html); $html=str_replace(" ",'',$html); $html=str_replace(" ",'',$html); $html=str_replace(" ",'',$html); $html=str_replace(chr(13),'',$html); $html=str_replace(array("\r\n","\n","\r"),'',$html); return $html; } //去掉HTML样式style function removeA_Style($html){ $html=str_replace(" ",'',$html); $html=str_replace(" ",'',$html); $html=str_replace(" ",'',$html); $html=preg_replace("/style=.+?['|\"]/i",'',$html); $html=preg_replace("/]*>(.*?)<\/a>/is", "$1",$html); return $html; } //url base64编码 function urlsafe_b64encode($string) { $data = base64_encode($string); $data = str_replace(array('+','/','='),array('-','_',''),$data); return $data; } //url base64解码 function urlsafe_b64decode($string) { $data = str_replace(array('-','_'),array('+','/'),$string); $mod4 = strlen($data) % 4; if ($mod4) { $data .= substr('====', $mod4); } return base64_decode($data); } function CutAbnormalHtml($str){//去掉yi2,zhu2,shang2的非法格式 $str=str_replace(array("\r\n", "\r", "\n",chr(13),"↵"),'',$str); $str=str_replace(array("", ""),'
',$str); $str=str_replace(array("", "","
", "
","", ""),'',$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 .= ""; $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; } ?>