1. Html_entity_decode (): Converts an HTML entity to a character.
Eg: $str = "Just atest & & #039; Learn to use & #039; ";
echo Html_entity_decode ($STR);
echo "<br/>";
Echo Html_entity_decode ($str, ent_quotes);
echo "<br/>";
Echo Html_entity_decode ($str, ent_noquotes);
The output is as follows:
Just a Test & ' learn to use '
Just a Test & ' learn to use '
Just a Test & ' learn to use '
2. Htmlentities (): Converts a character to an HTML entity.
Eg: $str = "Just a Test & ' learn to use '";
Echo htmlentities ($str, Ent_compat);
echo "<br/>";
Echo htmlentities ($str, ent_quotes);
echo "<br/>";
Echo htmlentities ($str, ent_noquotes);
The output is as follows:
Just a Test & ' learn to use '
Just a Test & ' learn to use '
Just a Test & ' learn to use '
View the source code as follows:
Just a test & ' Learn to use ' <br/>
Just a test & & #039; learn to use& #039; <br/>
Just a test & ' Learn to use '
3. Addslashes (): Adds a backslash before the specified predefined character
Predefined characters include: Single quotation mark ('), double quotation mark ("), backslash (\), NULL
By default, PHP instruction MAGIC_QUOTES_GPC is on, and automatically runs Addslashes () for all get, POST, and cookie data. Do not use Addslashes () for strings that have been MAGIC_QUOTES_GPC escaped, because this results in double-layer escaping. You can use the function GET_MAGIC_QUOTES_GPC () to detect this situation.
Eg: $str 3= "\ just a" \ "test";
Echoaddslashes ($str 3);
Output:
\ \ just a \ ' \ "Test
4. Stripslashes (): Remove the backslash added by the addslashes function
Eg: $str 4= "\ \ Just a \ '" Test ";
Echo stripslashes ($str 4);
Output:
Just a ' "test
5, Htmlspecialchars (): Convert some of the predefined characters to HTML entities.
Predefined characters including:& (and) become &
"(double quotes) become "
' (single quotes) become & #039;
< (less than) becomes <
> (greater than) becomes >
Eg: $str 5 = "Just atest & ' Learn to use '";
Echo Htmlspecialchars ($str 5, Ent_compat);
echo "<br/>";
Echo Htmlspecialchars ($str 5, ent_quotes);
echo "<br/>";
Echo Htmlspecialchars ($str 5, ent_noquotes);
Output:
Just a Test & ' learn to use '
Just a Test & ' learn to use '
Just a Test & ' learn to use '
View Source code: Just a Test & ' Learn to use ' <br/>
Just a test & & #039; learn to use& #039; <br/>
Just a test & ' Learn to use '
6, Htmlspecialchars_decode (): Convert some of the predefined HTML entities to characters.
HTML entities that will be decoded include:& Become & (and No.)
" Become "(double quotes)
& #039; Become ' (single quote)
< Become < (less than)
> Become > (greater than)
Eg: $str 6 = "Just atest & & #039; learn to use& #039; ";
Echo Htmlspecialchars_decode ($str 6);
echo "<br/>";
Echo Htmlspecialchars_decode ($str 6, ent_quotes);
echo "<br/>";
Echo Htmlspecialchars_decode ($str 6, ent_noquotes);
Output:
Just a Test & ' learn to use '
Just a Test & ' learn to use '
Just a Test & ' learn to use '
View Source code:
Just a Test & & #039; Learn to use & #039; <br/>
Just a Test & ' learn to use ' <br/>
Just a Test & & #039; Learn to use & #039;
So far, I think we should understand the basic trial of several functions.
About the use of htmlentities, Htmlspecialchars, addslashes