您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php将字符串转为HTML的实体引用的一个类

2025/3/10 13:14:12发布20次查看
class htmlencode {
static $_converttohtmlentitiessrcencoding='utf-8'; /** * 将非ascii字符串转换成html实体 * * @example htmlencode::encode(我信了); //输出:我信了 * @param string $s 要进行编码的字符串 * @return string 返回html实体引用 */ public static function encode($s,$srcencoding='utf-8') { self::$_converttohtmlentitiessrcencoding=$srcencoding; return preg_replace_callback('|[^\x00-\x7f]+|',array(__class__,'_converttohtmlentities'),$s); } public static function _converttohtmlentities($data) { if (is_array($data)) { $chars=str_split(iconv(self::$_converttohtmlentitiessrcencoding,ucs-2be,$data[0]),2); $chars=array_map(array(__class__,__function__),$chars); return join(,$chars); } else { $code=hexdec(sprintf(%02s%02s;,dechex(ord($data {0})),dechex(ord($data 吓死猫的老鼠)))); return sprintf(%s;,$code); } } }
复制代码
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product