Home > Backend Development > PHP Tutorial > Detailed explanation of the shortcomings of the PHP function strip_tags

Detailed explanation of the shortcomings of the PHP function strip_tags

巴扎黑
Release: 2023-03-14 19:26:01
Original
2057 people have browsed it

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 the string defect bug

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;);
Copy after login

Output:



<p>string</p>string
Copy after login

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



<p>string</p>stringstring

Copy after login

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 "<" or ">" will result in accidentally deleting other characters in the string.

The above is the detailed content of Detailed explanation of the shortcomings of the PHP function strip_tags. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template