php removes THE html tag details the difference between strip_tags and htmlspecialchars

  • 2020-06-23 00:00:06
  • OfStack

strip_tags
Remove the HTML and PHP tags.
Grammar: string strip_tags(string str)
Return value: String
Function type: data processing
Content description
This function removes any HTML and PHP token strings contained in the string. An error is also returned if the HTML and PHP tags of the string were originally incorrect, such as missing a greater than symbol. This function has the same function as fgetss().

htmlspecialchars
Convert special characters to HTML format.
Grammar: string htmlspecialchars(string string);
Return value: String
Function type: data processing
This function converts a special character to the string format of HTML ( & . ; ). Perhaps the most commonly used situation is to deal with customer messages message board.
& (and) transform into & amp;
"(double quotes) & quot;
< Theta is less than theta & lt;
> Theta is greater than theta & gt;
"(single quote) converted to & #039;
This function converts only the above special characters and does not all convert to ASCII as specified by HTML.

<?php  
     $new  = htmlspecialchars( "<a href='test'>Test</a>" , ENT_QUOTES);  
     echo   $new ;   
?> 

Results: & lt;a href= & #039;test & #039; & gt;Test & lt;/a & gt;

Related articles: