Home  >  Article  >  Backend Development  >  Analysis of the difference between strip_tags and htmlspecialchars in removing html tags in php

Analysis of the difference between strip_tags and htmlspecialchars in removing html tags in php

WBOY
WBOYOriginal
2016-07-25 08:58:17968browse
This article introduces the difference between two functions for removing HTML tags in PHP, strip_tags and htmlspecialchars. Friends who are useful may wish to refer to it.

First, let’s look at the strip_tags function. Remove HTML and PHP tags. Syntax: string strip_tags(string str); Return value: string Function type: Data processing Content description This function can remove any HTML and PHP markup strings contained in the string. If the HTML and PHP tags of the string are originally wrong, for example, the greater than symbol is missing, an error will also be returned. This function has the same function as fgetss().

Let’s look at the htmlspecialchars function again. Convert special characters into HTML format. Syntax: string htmlspecialchars(string string); Return value: string Function type: Data processing This function converts special characters into HTML string format ( &....; ). The most commonly used occasion may be the message board for processing customer messages. & (and) converted to & " (double quotation marks) converted to " ​ (greater than) converted to > ​'' (single quote) converted to ' This function only converts the above special characters, and does not convert all of them into the ASCII conversion specified by HTML.

Example:

<?php 
$new = htmlspecialchars( "Test" , ENT_QUOTES); 
echo $new ;
//by bbs.it-home.org
?> 

Output result: Test



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