Home  >  Article  >  Backend Development  >  Detailed introduction to PHP common function strip_tags

Detailed introduction to PHP common function strip_tags

零下一度
零下一度Original
2017-06-15 14:26:271756browse

This article mainly introduces the relevant information on the detailed explanation of the PHP function strip_tags to handle string defect bugs. Friends in need can refer to it

Detailed explanation of the PHP function strip_tags to handle string defect bugs

PHP function strip_tags() is a commonly used function, which can strip HTML, XML and PHP tags from strings. It greatly facilitates the operation of strings, but the strip_tags() function has bugs. Since strip_tags() cannot verify incomplete or damaged HTML tags, more data will be deleted.

Example:


##

$str = &#39;<p>string</p>string<string<b>hello</b><p>string</p>&#39;;
 
echo strip_tags($str, &#39;<p>&#39;);

Output:



<p>string</p>string

Filter a4b561c25d9afb9ac8dc4d70affff419 tags through the strip_tags function. In fact, I hope to get the following result:



<p>string</p>stringstring

As a result, we failed to get the expected result. In fact, Because of the angle bracket to the left of the third string in the string, the strip_tags function accidentally deleted other characters.


After searching for PHP related documents, I found that the strip_tags function has a warning: Since strip_tags() cannot actually verify HTML, incomplete or damaged tags will cause more data to be deleted.


Since the integrity of HTML tags cannot be verified, encountering strings containing "0f2b9e4ada5fafd77945e69dc6bec0d7" will result in accidentally deleting other characters in the string.

The above is the detailed content of Detailed introduction to PHP common function strip_tags. 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