Home  >  Article  >  Backend Development  >  How to use php html_entity_decode function

How to use php html_entity_decode function

青灯夜游
青灯夜游Original
2019-05-27 10:06:332644browse

html_entity_decode() function is used to convert HTML entities into characters. The syntax is html_entity_decode(string, flags, character-set).

How to use php html_entity_decode function

php How to use the html_entity_decode() function?

html_entity_decode() function converts HTML entities into characters.

Syntax

html_entity_decode(string,flags,character-set)

Parameters:

1, string: required. Specifies the string to decode.

2. flags: optional. Specifies how quotation marks are handled and which document type is used.

Available quote types:

● ENT_COMPAT - Default. Only double quotes are decoded.

● ENT_QUOTES - Decode double and single quotes.

● ENT_NOQUOTES - Do not decode any quotes.

Additional flags specifying the document type used:

● ENT_HTML401 - Default. Code processed as HTML 4.01.

● ENT_HTML5 - Process code as HTML 5.

● ENT_XML1 - As XML 1 processing code.

● ENT_XHTML - as XHTML processing code.

3. character-set: optional. String value specifying the character set to use. Allowed values:

● UTF-8 - Default. ASCII compatible multi-byte 8-bit Unicode

● ISO-8859-1 - Western Europe

● ISO-8859-15 - Western Europe (added euro symbol to ISO-8859-1 Missing French and Finnish letters)

● cp866 - DOS-specific Cyrillic character set

● cp1251 - Windows-specific Cyrillic character set

● cp1252 - Windows-specific 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 extension

● Shift_JIS - Japanese

● EUC-JP - Japanese

● MacRoman - Character set used by Mac operating systems

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

Return value: Return the converted string

Let’s take an example to see how to use the php strstr() function.

Example 1: Convert HTML entities to characters

<?php
$str = "Bill & &#039;Steve&#039;";
echo html_entity_decode($str, ENT_COMPAT); // 只转换双引号
echo "<br>";
echo html_entity_decode($str, ENT_QUOTES); // 转换双引号和单引号
echo "<br>";
echo html_entity_decode($str, ENT_NOQUOTES); // 不转换任何引号
?>

Output:

How to use php html_entity_decode function

Example 2: Convert HTML entities to characters by using Western European character sets

<?php
$str = "My name is Øyvind Åsane. I&#39;m Norwegian.";
echo html_entity_decode($str, ENT_QUOTES, "ISO-8859-1");
?>

HTML output of the above code (view source code):

<!DOCTYPE html>
<html>
<body>
My name is ?yvind ?sane. I&#39;m Norwegian.
</body>
</html>

Browser output of the above code :

My name is ?yvind ?sane. I&#39;m Norwegian.

The above is the detailed content of How to use php html_entity_decode function. 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