Detailed explanation of the shortcomings of the PHP function strip_tags

巴扎黑
Release: 2023-03-14 19:26:01
Original
1993 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 = '

string

stringhello

string

'; echo strip_tags($str, '

');

Copy after login

Output:



string

string
Copy after login

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



string

string string

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!