本文实例讲述了php清除字符串中所有无用标签的方法。分享给大家供大家参考。具体实现方法如下:
很多时候需要输出一些 “纯” 字符串,也就是去除任何杂质,例如 html 标签、空格之类的文本,输出的摘要就是如此,下面的这个函数可以帮你实现着一点.
php实例代码如下:
function bing_string_cleanr( $string ){
$string = trim( $string );
$string = strip_tags( $string );
$string = htmlspecialchars( $string, ent_quotes, 'utf-8' );
$string = str_replace( "n", "", $string );
$string = trim( $string );
return $string;
}
使用方法如下:
echo bing_string_cleanr( '内 容 <br> <html> asdfeiuonsdfje' );
php删除空白,代码如下:
<?php
$str = " this line containstliberal rn use of whitespace.nn";
// first remove the leading/trailing whitespace
//去掉开始和结束的空白
$str = trim($str);
// now remove any doubled-up whitespace
//去掉跟随别的挤在一块的空白
$str = preg_replace('/s(?=s)/', '', $str);
// finally, replace any non-space whitespace, with a space
//最后,去掉非space 的空白,用一个空格代替
$str = preg_replace('/[nrt]/', ' ', $str);
// echo out: 'this line contains liberal use of whitespace.'
echo "<pre>{$str}</pre>";
?>
希望本文所述对大家的php程序设计有所帮助。
如对本文有疑问,
点击进行留言回复!!
相关文章:
-
-
-
-
-
-
-
-
-
管理后台无限级菜单
管理后台菜单遍历很久就想做一个通用的管理后台出来,一直太懒没做,今天开始粗略搞了一下,只是先把框架搭建好,菜单栏...
[阅读全文]
-
桥接模式学习总结
桥接模式引言假如一个系统需要加入报表模块,主要的开发点是数据的获取和报表的显示方式。数据的获取可能是从系统数据库...
[阅读全文]
-
网友评论