php smalltext,内容页输出内容简介smalltext过滤特殊字符及空格函数

30906a7d8b86944e6ae44f13e04b470e.png

帝国cms内容页模板的描述标签,是直接输出内容标题,新闻在发布时会自动生成smalltext简介字段,但我们如果直接在页面上输出简介字段,经常会带有特殊字符或者带有换行。

如何在帝国cms的内容页输出不换行且没有特殊字符的内容简介?

方法如下:function Cmsdx_format_html($str){

$str=trim($str);

$str=str_replace('&','',$str);

$str=str_replace('ldquo;','“',$str);

$str=str_replace('rdquo;','”',$str);

$str=str_replace('middot;','·',$str);

$str=str_replace('lsquo;','‘',$str);

$str=str_replace('rsquo;','’',$str);

$str=str_replace('hellip;','…',$str);

$str=str_replace('mdash;','—',$str);

$str=str_replace('ensp;','',$str);

$str=str_replace('emsp;','',$str);

$str=str_replace('nbsp;','',$str);

$str=str_replace(' ','',$str);

$str=str_replace('t','',$str);

$str=str_replace('rn','',$str);

$str=str_replace('r','',$str);

$str=str_replace('n','',$str);

$str=str_replace(' ','',$str);

$str = preg_replace('/s(?=s)/','', $str);// 接着去掉两个空格以上的

$str = preg_replace('/[nrt]/',' ', $str);// 最后将非空格替换为一个空格

return trim($str);

}

我们将上述函数放到/e/class/userfun.php 中,这里是存储用户的自定义函数。

接下来在内容页描述的meta标签中调用如下标签:=Cmsdx_format_html($navinfor['smalltext'])?>

注意外层一定要包裹我们写的自定义函数,这样就可以实现无特殊格式的输出smalltext简介字段了。

523阅读

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值