方法二,自定义函数去除 复制 function cutstr_html($string, $sublen){ $string = strip_tags($string); $string = preg_replace"> 跳转到主内容
websoft网络软件专家 - 深耕网络技术,打造实用软件!

php如何清除html标签(除空格和换行)

这篇文章主要讲了 php 如何清除 html 标签(除空格和换行),有一定的的参考价值,感兴趣的朋友可以看看,希望对你有所帮助! 方法一,strip_tags()剥去字符串中的 HTML 标签:
world!");//运行结果:Hello world!?>
方法二,自定义函数去除
function cutstr_html($string, $sublen){ $string = strip_tags($string); $string = preg_replace ('/\n/is', '', $string); $string = preg_replace ('/ | /is', '', $string); $string = preg_replace ('/ /is', '', $string); preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/", $string, $t_string); if(count($t_string[0]) - 0 > $sublen) $string = join('', array_slice($t_string[0], 0, $sublen))."…"; else $string = join('', array_slice($t_string[0], 0, $sublen)); return $string; }
【相关教程推荐 1. php编程从入门到精通全套视频教程 PHP 8.5.5 PHP 8.5.5 是 PHP 8.5 分支的维护更新版本。该版本延续了“小步快跑”的迭代逻辑,通过深度错误修复、底层性能微调以及安全加固,旨在为开发者提供一个更健壮、更高效的运行环境。该版本严格遵守语义化版本规范,不包含破坏性变更。 下载 立即学习 “ PHP免费学习笔记(深入) ”; 2. php从入门到精通 3. bootstrap教程

相关文章