php怎么判断字符串中是否包含html标签?

PHPz
Release: 2020-09-05 11:57:13
Original
2977 people have browsed it

php判断字符串中是否包含html标签的方法:首先使用“strip_tags”函数处理字符串;然后使用if语句判断处理后的字符串“str2”和原字符串“str”是否相等;最后用“strip_tags”函数剥离字符串中的html标签即可。

php怎么判断字符串中是否包含html标签?

php怎么判断字符串中是否包含html标签?

代码示例:

<?php
header("Content-Type: text/html; charset=utf-8");
function judgeHtml($str){
 if($str != strip_tags($str)){
  echo &#39;有&#39;;
 }else{
  echo &#39;无&#39;;
 }
}
judgeHtml(&#39;<html>a&#39;);
echo &#39;<br />&#39;;
judgeHtml(&#39;a&#39;);
?>
Copy after login

输出:

有
无
Copy after login

说明:

strip_tags() 函数剥去字符串中的 HTML、XML 以及 PHP 的标签。

注释:该函数始终会剥离 HTML 注释。这点无法通过 allow 参数改变。

返回值:返回被剥离的字符串。

更多相关知识,请访问 PHP中文网!!

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!