PHP converts a string into an HTML object reference. ClassHtmlEncode {static $ _ convertToHtmlEntitiesSrcEncodingUTF-8; *** convert a non-ASCII string to an HTML entity *** @ exampleHtmlEncode: encode (I believe); output: #25105; #20449; class HtmlEncode {
Static $ _ convertToHtmlEntitiesSrcEncoding = 'utf-8 ';
/**
* Convert a non-ASCII string to an HTML object
*
* @ Example HtmlEncode: encode ("I Believe"); // output: I believe
* @ Param string $ s the string to be encoded
* @ Return string returns the HTML object reference www.2cto.com
*/
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 ("% 02 s % 02 s;", dechex (ord ($ data {0 })), dechex (ord ($ data {1 }))));
Return sprintf ("& # % s;", $ code );
}
}
}
Http://www.bkjia.com/PHPjc/478431.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/478431.htmlTechArticleclass HtmlEncode {static $ _ convertToHtmlEntitiesSrcEncoding = UTF-8;/*** convert a non-ASCII string to an HTML entity *** @ example HtmlEncode: encode (I believe); // output: #25105; #20449 ;...