Notes on the use of strip_tags() function in php

黄舟
Release: 2023-03-17 18:34:01
Original
1766 people have browsed it

php strip_tags() function is to remove the HTML, XML and PHP tags in string and return the tags after removal string, but you need to pay attention when using the php strip_tags() function. Today I will introduce to you the precautions for using the strip_tags() function in php!

Example:

<?php
$text = &#39;<p>Test paragraph.</p>
<!-- Comment --> 
<a href="#fragment">Other text</a>&#39; ;
echo strip_tags ( $text );
echo "\n" ;

// 允许 <p> 和 <a>
echo strip_tags ( $text , &#39;<p><a>&#39; );
?>
Copy after login

When I was writing a blog project today, I found this function, it will cause a page exception. After searching for a long time, I found the reason. The code here is as follows:

if(mb_strlen($blog[&#39;body&#39;]) >  300){
	echo mb_substr(<span style="color:#ff0000;">strip_tags($blog[&#39;body&#39;]," ")</span>, 0,  300,&#39;utf-8&#39;)."......";//注意这里允许空格
	echo "<span class = &#39;more_blog&#39;><a href = &#39;/blog/view/id/".$blog[&#39;id&#39;]."&#39;>阅读全文>></a></span>";
	echo "<hr>";
}
Copy after login

Summary:

When we publish an article, if there are spaces in the first 100 words, an exception will occur, so in function parameters, spaces must be retained when filtering, I believe Friends, please pay attention to the use of strip_tags() function. I hope it will be helpful to your work!

Related recommendations:

strip_tags() in php only filters a certain tag in the string Example analysis

Detailed explanation of the shortcomings of the PHP function strip_tags

Common PHP functions Detailed introduction to strip_tags

php String function strip_tags() usage summary

The above is the detailed content of Notes on the use of strip_tags() function in php. 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