Home > Backend Development > PHP Tutorial > Example development of php converting strings into html entities

Example development of php converting strings into html entities

黄舟
Release: 2023-03-15 08:52:02
Original
3278 people have browsed it

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实体引用
Copy after login

The final running result is as shown below:

Example development of php converting strings into html entities

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template