帝国CMS截取内容简介函数,过滤特殊字符及空格方法

2022-03-09   来源:新闻资讯
帝国cms内容页模板的描述标签,是直接输出内容标题,这个在seo优化当中还是有一定影响的,新闻在发布时会自动生成smalltext简介字段,但我们如果直接在页面上输出简介字段,经常会带有特殊字符或者带有换行,这个也是非常不好的。接下来跟cms大学小编一起学习如何在帝国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('\r\n','',$str);   

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

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

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

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

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

return trim($str); 



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

接下来在内容页描述的meta标签中调用如下标签:

<?=Cmsdx_format_html($navinfor['smalltext'])?>

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

帝国CMS截取内容简介函数,过滤特殊字符及空格方法

http://m.gdfshaiyu.com/gongwen/122091.html

展开更多 50 %)
分享

热门关注

新闻及传播起源于人类社会性的生产劳动实践。这是的基本思想。

新闻资讯

坚持正确舆论导向,高度重视传播手段建设和创新,提高新闻舆论__

新闻资讯

明年高校毕业生达910万

新闻资讯

流失文物马首铜像回家

新闻资讯

拜登拟提名耶伦任财长

新闻资讯

飞天奖是什么奖

新闻资讯

CNN是什么的缩写?

新闻资讯

什么是党的新闻舆论工作必须遵循的基本方针。

新闻资讯

《新闻联播》原来的名字叫:

新闻资讯

美国新闻奖的最高奖项是:

新闻资讯