Home>Article>Backend Development> PHP implements a class for converting HTML entity numbers and non-ASCII strings to each other

PHP implements a class for converting HTML entity numbers and non-ASCII strings to each other

jacklove
jacklove Original
2018-06-08 23:08:27 2272browse

HTML entity symbols are used to implement reserved characters or to express some common characters that cannot be input by the keyboard. The default character set in most browsers is ISO-8859-1. HTML entity symbols are often used in web design.

For example:

字符 实体名称 实体编号 描述 & & & and符号,与 " " " 引号 © © © 版权标志 ® ® » 注册标志 ™ ™ ™ 商标标志 “ “ “ 左双引号 ” ” ” 右双引号 ‘ ‘ ‘ 做单引号 ’ ’ ’ 右单引号

Due to work needs, I wrote a class for converting HTML entity numbers and non-ASCII strings. The code is as follows:

HtmlEntitie .class.php

demo.php

更多资讯可关注本人微信号:fdipzone-idea

PHP implements a class for converting HTML entity numbers and non-ASCII strings to each other

您的支持是我最大的动力,谢谢!

';// 字符串转为HTML实体编号$cstr = HtmlEntitie::encode($str);echo '字符串转为HTML实体编号'.PHP_EOL;echo $cstr.PHP_EOL.PHP_EOL;// HTML实体编号转为字符串echo 'HTML实体编号转为字符串'.PHP_EOL;echo HtmlEntitie::decode($cstr);?>

Output:

字符串转为HTML实体编号

更多资讯可关注本人微信号:fdipzone-idea

PHP implements a class for converting HTML entity numbers and non-ASCII strings to each other

您的支持是我最大的动力,谢谢!

HTML实体编号转为字符串

更多资讯可关注本人微信号:fdipzone-idea

PHP implements a class for converting HTML entity numbers and non-ASCII strings to each other

您的支持是我最大的动力,谢谢!


Both of them can be displayed normally in the browser, as shown below:

PHP implements a class for converting HTML entity numbers and non-ASCII strings to each other

This article explains how to convert HTML entity numbers and non-ASCII strings in PHP Class-related knowledge, please pay attention to the php Chinese website for more related content.

Related recommendations:
php creates a unique number class based on the auto-incremented id

About mysql View the currently used configuration file my.cnf The method explains

How to determine whether a point is within the specified polygon area through mysql

The above is the detailed content of PHP implements a class for converting HTML entity numbers and non-ASCII strings to each other. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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