Home > Backend Development > PHP Tutorial > One detail you need to pay attention to when using the php strip_tags() function

One detail you need to pay attention to when using the php strip_tags() function

怪我咯
Release: 2023-03-08 06:34:01
Original
4219 people have browsed it

php The strip_tags() function removes HTML, XML and PHP tags from the string and returns the string after removing the tags. However, there is a detail that needs to be paid attention to when using the php strip_tags() function, that is, when using php strip_tags( ) function, if the HTML tag is incomplete or damaged, more data will be deleted. This article will tell you about the consequences of using the strip_tags() function to remove incomplete HTML tags. Let’s take a look.

Look directly at the example below, the code is as follows:

<?php
$name="<p>string</p>string-1<string<b>hello</b><p>string-2</p>";

$tags=strip_tags($name,&#39;<p>&#39;);

echo $tags;
?>
Copy after login

Filtering by strip_tags($name, '

'), we may expect to get the following results:

One detail you need to pay attention to when using the php strip_tags() function

But the actual result of running the code is like this

One detail you need to pay attention to when using the php strip_tags() function

What is the reason for this? If you carefully observe the variable $name in the above code, you will find that one tag in the string in $name is incomplete. This is because the strip_tags() function cannot actually verify the integrity of the HTML tag. If the HTML tag is incomplete, it will cause More data is deleted. Therefore, you must pay attention to this when using the php strip_tags() function.

【Recommended related articles】

php remove string tags strip_tags() function example

Use Detailed explanation of php strip_tags() function retaining multiple HTML tag instances

The above is the detailed content of One detail you need to pay attention to when using the php strip_tags() function. 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