Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How php converts characters to entities

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how php turns characters into entities". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how php turns characters into entities".

Php will characters into entities: 1, the use of htmlentities () function, characters can be converted into HTML entities; 2, the use of htmlspecialchars () function, some predefined characters ("&", "", etc.) can be converted into HTML entities.

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

Php converts characters to entities

1. Use the htmlentities () function

The htmlentities () function converts characters to HTML entities.

Syntax:

The htmlentities (string,flags,character-set,double_encode) parameter is required to describe string. Specifies the string to be converted. Flags is optional. Specifies how to handle quotation marks, invalid encodings, and which document type to use.

Available quotation mark types:

ENT_COMPAT-default. Encodes only double quotation marks.

ENT_QUOTES-encodes double and single quotation marks.

ENT_NOQUOTES-No quotation marks are encoded.

Invalid encoding:

ENT_IGNORE-ignores invalid encoding instead of letting the function return an empty string. It should be avoided as much as possible, as this may have an impact on security.

ENT_SUBSTITUTE-replaces the invalid encoding with a specified character with the Unicode substitution character U+FFFD (UTF-8) or & # FFFD; instead of returning an empty string.

ENT_DISALLOWED-replaces the invalid code point in the specified document type with the Unicode substitution character U+FFFD (UTF-8) or & # FFFD;.

An additional flags that specifies the type of document to use:

ENT_HTML401-default. Handle the code as HTML 4.01.

ENT_HTML5-handles the code as HTML5.

ENT_XML1-handles the code as XML1.

ENT_XHTML-handles the code as XHTML.

Character-set is optional. A string that specifies the character set to be used.

Allowed values:

UTF-8-default. ASCII is compatible with multi-byte 8-bit Unicode

ISO-8859-1-Western Europe

ISO-8859-15-Western Europe (add euro symbol + missing French and Finnish letters in ISO-8859-1)

Cp866-DOS dedicated Cyrillic character set

Cp1251-Windows dedicated Cyrillic character set

Cp1252-Windows dedicated Western European character set

KOI8-R-Russian

BIG5-traditional Chinese, mainly used in Taiwan

GB2312-simplified Chinese, national standard character set

BIG5-HKSCS-Big5 with Hong Kong expansion

Shift_JIS-Japanese

EUC-JP-Japanese

MacRoman-character set used by the Mac operating system

Note: in versions prior to PHP 5.4, unrecognized character sets were ignored and replaced by ISO-8859-1. As of PHP 5.4, unrecognized character sets will be ignored and replaced by UTF-8.

Double_encode is optional. A Boolean value that specifies whether to encode an existing HTML entity.

TRUE-default. Each entity will be converted.

FALSE-existing HTML entities are not encoded.

Example: convert some characters to HTML entities by using the Western European character set:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report