Php converts a string into a class referenced by an HTML object. Copy the code as follows: classHtmlEncode {static $ _ convertToHtmlEntitiesSrcEncodingUTF-8; *** convert a non-ASCII string to an HTML entity *** @ exampleHtmlEncode: encode (I believe
The code is as follows:
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 HTML object reference
*/
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 );
}
}
}
The http://www.bkjia.com/PHPjc/326471.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/326471.htmlTechArticle code is as follows: class HtmlEncode {static $ _ convertToHtmlEntitiesSrcEncoding = 'utf-8';/*** converts a non-ASCII string to an HTML entity ** @ example HtmlEncode :: encode ("I believe...