How to convert php string to html
This article mainly explains "how to convert php string into html". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to turn php string into html".
The method of converting php string to html: 1, converting the special characters in the string into html entities through htmlentities (); 2, converting the special characters in the string into html entities through the htmlspecialchars () function.
Operating environment of this article: Windows7 system, PHP7.1 version, Dell G3 computer
How to convert php string to html?
Conversion function between string and html in PHP
In the general communication process, you may encounter many characters that are not included in the document text encoding, or characters that cannot be entered on the keyboard. For example, copyright symbols (©), penny symbols (information) and grammatical accents belong to this kind of characters. In order to overcome these shortcomings, a set of unified key codes, called character entity references, are specially designed.
1 html htmlentities (), which converts special characters in a string into htmlentities.
String htmlentities (string $str,int $quote_style,int $charset,boolean $double_encode), because quotation marks have a special meaning, you can choose how to handle quotation marks through the $quote_style parameter, its value: ENT_COMPAT, convert double quotes, ignore single quotes, which is the default; ENT_NOQUOTES, ignore double and single quotes; ENT_QUOTES, convert double quotes and single quotes. The $charset parameter determines the character set used for the conversion. If charset is omitted, it defaults to ISO-8859-1. $double_encode prevents htmlentities () from encoding HTML entities that already exist in the string.
Such as: