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 does php convert html code into an entity

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces "php how to convert html code into entities", in daily operation, I believe many people in php how to convert html code into entities on the question of doubt, Xiaobian consulted all kinds of information, sorted out simple and easy to use operation methods, hope to answer "php how to convert html code into entities" doubts helpful! Next, please follow the small series to learn together!

The php function that converts html code into entities is htmlspecialchars(), which converts predefined characters into HTML entities using the syntax "htmlspecialchars(string,flags,character,double_encode)."

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

The php function that converts html code into entities is htmlspecialchars().

Examples:

Description:

The htmlspecialchars() function is used to convert some predefined characters into HTML entities and return the converted new string, leaving the original string unchanged. If string contains an invalid encoding, returns an empty string unless ENT_IGNORE or ENT_SUBSTITUTE flags are set;

The predefined characters to be converted are:

&: Convert to &

": convert to"

': convert to become'

htmlspecialchars() function has four parameters, the first parameter specifies the string to be converted; the second parameter specifies how to handle quotation marks, invalid encoding, and which document type to use; the third parameter is also optional, specifying the string of the character set to use; the fourth parameter is also optional, specifying whether to encode the Boolean value of the existing HTML entity (TRUE: each entity will be converted;FALSE: existing HTML entities will not be encoded);

htmlspecialchars() function syntax format:

$str = htmlspecialchars(string,flags,character,double_encode);

parameter description

Parameter Description string Required. Specifies the string to convert. flags

Optional. Specify how to handle quotation marks, invalid encoding, and which document type to use.

Available quote types:

ENT_COMPAT -Default. Encode double quotes only.

ENT_QUOTES -Codes double quotes and single quotes.

ENT_NOQUOTES -does not encode any quotes.

Invalid code:

ENT_IGNORE -Ignore invalid encodings instead of having the function return an empty string. It should be avoided as much as possible because it may have an impact on safety.

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

ENT_DISALLOWED -Substitutes invalid code points in the specified document type with Unicode alternate characters U+FFFD (UTF-8) or.

Additional flags specifying the document type used:

ENT_HTML401 -Default. Handles code as HTML 4.01.

ENT_HTML5 -Handles code as HTML 5.

ENT_XML1 -Process code as XML1.

ENT_XHTML -Handles code as XHTML.

character

Optional. A string specifying the character set to use.

Allowed values:

UTF-8-Default. ASCII compatible multibyte 8-bit Unicode

ISO-8859-1 -Western Europe

ISO-8859-15 -Western Europe (Euro symbol added + missing French and Finnish letters from ISO-8859-1)

cp866 - DOS Cyrillic character set

cp1251 - Windows specific Cyrillic character set

cp1252 -Western European Character Set for Windows

KOI8-R -Russian

BIG5 -Traditional Chinese, mainly used in Taiwan

GB2312 -Simplified Chinese, National Standard Character Set

BIG5-HKSCS -Big5 with Hong Kong Extension

Shift_JIS -Japanese

EUC-JP -Japanese

MacRoman -Character set used by Mac operating system

Note: Before PHP 5.4, unrecognized character sets were ignored and replaced by ISO-8859-1. As of PHP 5.4, unrecognized character sets are ignored and replaced by UTF-8.

double_encode

Optional. Boolean specifying whether to encode an existing HTML entity.

TRUE -Default. Each entity will be transformed.

FALSE -does not encode existing HTML entities.

Return value:

Returns the converted string. If string contains an invalid encoding, returns an empty string unless ENT_IGNORE or ENT_SUBSTITUTE flags are set.

At this point, the study of "how php converts html code into entities" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

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