Home > php教程 > php手册 > php如何清除html标签(除空格和换行)

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2018-10-24 15:11:38
forward
1489 people have browsed it

这篇文章主要讲了php如何清除html标签(除空格和换行),有一定的的参考价值,感兴趣的朋友可以看看,希望对你有所帮助!

方法一,strip_tags()剥去字符串中的 HTML 标签:

<?phpecho strip_tags("Hello <b>world!</b>");//运行结果:Hello world!?>
Copy after login

方法二,自定义函数去除

function cutstr_html($string, $sublen){
    $string = strip_tags($string);    
    $string = preg_replace (&#39;/\n/is&#39;, &#39;&#39;, $string);    
    $string = preg_replace (&#39;/ | /is&#39;, &#39;&#39;, $string);   
    $string = preg_replace (&#39;/ /is&#39;, &#39;&#39;, $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(&#39;&#39;, array_slice($t_string[0], 0, $sublen))."…";    
    else 
       $string = join(&#39;&#39;, array_slice($t_string[0], 0, $sublen));   
    return $string;
}
Copy after login

【相关教程推荐

1. php编程从入门到精通全套视频教程 

2. php从入门到精通  

3. bootstrap教程 

Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template