字符内容转换

<?php
// getallheaders();
// gethostbyname()
//字符内容转换
function unhtml($content){
    $content=htmlspecialchars($content);
    $content=str_replace(chr(13), "<br>", $content);
    $content=str_replace(chr(32), "&nbsp", $content);
    $content=str_replace("[_[", "<", $content);
    $content=str_replace(")_)", ">", $content);
    $content=str_replace("|_|", "&nbsp", $content);
    return trim($content);
}
//控制文本数据输出
function msubstr($str,$start,$len){
    $strlen=$start+$len;
    $tmp=0;
    for ($i=0; $i <$strlen ; $i++) {
        //大于0xa0表示字符串为汉字
        if(ord(substr($str,$i,1))>0xa0){
            //是汉字,取2个字符给到变量

            $tmp.=substr($str,$i,2);
            $i++;
        }else{
            //不是汉字,取一个字符
            $tmp.=substr($str, $i,1);
        }
    }
    return $tmp;
}

原文地址:https://www.cnblogs.com/lemon66/p/4109274.html