htmlEntity symbols are used to implement reserved characters or express some common characters that cannot be input by the keyboard. The default character set in most browsers is ISO-8859-1. We often use html entity symbols in web design, so how do we use php to convert non-ASCII strings into HTML entities, encode the strings, and return HTML entity references.
Step one: Download the PHP class library we need for this lesson to convert strings into HTML entities: //m.sbmmt.com/xiazai/leiku/608
Step 2: After the download is complete, unzip the file to the local directory and create a new php file!
The third step: Call the class and instantiate it in the new php file:
<?php include_once "stringhtml.php"; //引入类库 $obj = new HtmlEncode; //实例化该类 //定义字符串以及编码 $str = "中文网"; $srcEncoding = "utf-8"; echo $obj->encode($str,$srcEncoding);//返回HTML实体引用
The final running result is as shown below:
The above is the detailed content of Example development of php converting strings into html entities. For more information, please follow other related articles on the PHP Chinese website!