Home >Backend Development >PHP Tutorial >Notes on the use of strip_tags() function in php
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 = '<p>Test paragraph.</p> <!-- Comment --> <a href="#fragment">Other text</a>' ; echo strip_tags ( $text ); echo "\n" ; // 允许 <p> 和 <a> echo strip_tags ( $text , '<p><a>' ); ?>
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['body']) > 300){ echo mb_substr(<span style="color:#ff0000;">strip_tags($blog['body']," ")</span>, 0, 300,'utf-8')."......";//注意这里允许空格 echo "<span class = 'more_blog'><a href = '/blog/view/id/".$blog['id']."'>阅读全文>></a></span>"; echo "<hr>"; }
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!