Explain the shortcomings of PHP function strip_tags

Source: Internet
Author: User
This article mainly describes the PHP function strip_tags processing string defects of the relevant data, the need for friends can refer to the following

Detailed PHP function strip_tags handling string defect bug

php function Strip_tags () is a commonly used function that strips HTML, XML, and PHP tags from a string. The operation of the string is greatly facilitated, but the strip_tags () function has a defective bug, because strip_tags () cannot verify that the HTML is incomplete or the broken label will result in more data being deleted.

Example:


$str = ' <p>string</p>string<string<b>hello</b><p>string</p> '; Echo strip_tags ($str, ' <p> ');

Output:


<p>string</p>string

Through the Strip_tags function filter <b> tags, I actually want to get the following result:


<p>string</p>string<stringhello<p>string</p>

Causes us not to get the desired result, in fact, because the string of the third string to the left of the angle bracket, the Strip_tags function mistakenly deleted other characters.

Find PHP-related documents found Strip_tags function has a warning: because Strip_tags () cannot actually validate HTML, incomplete or broken labels will result in more data being deleted.

Since you cannot verify the integrity of HTML tags, encountering strings that contain "<" or ">" causes other characters in the string to be mistakenly deleted.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.