第一步:下载我们本节课有需要的php将字符串转为html实体的类库:
第二步:下载完成之后将文件解压到本地目录下,在创建新的php文件!
第三步:在新的php文件中调用该类以及实例化:
<?php include_once "stringhtml.php"; //引入类库 $obj = new HtmlEncode; //实例化该类 //定义字符串以及编码 $str = "中文网"; $srcEncoding = "utf-8"; echo $obj->encode($str,$srcEncoding);//返回HTML实体引用
最后运行结果如下图所示:

| 欢迎光临 一起源码网 (https://www.171739.xyz/) | Powered by Discuz! X3.3 |