帝国CMS常用的过滤特殊字符及空格函数_帝国cms教程-大众资源网

帝国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('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概述字段了。

发表评论