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,'<p>'); echo $tags; ?>
Filtering by strip_tags($name, '
'), we may expect to get the following results:
But the actual result of running the code is like this
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!