温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

利用PHP怎么删除字符串中无用的标签

发布时间:2020-12-30 15:58:00 来源:亿速云 阅读:141 作者:Leah 栏目:开发技术

这篇文章给大家介绍利用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怎么删除字符串中无用的标签就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI