本站PbootCms模板板块实时同步更新AB网!客服QQ:229866246

帝国CMS截取内容简介并过滤特殊字符及空格

正文概述    2025-01-21 11:39:28  

帝国 CMS 截取内容简介并过滤特殊字符及空格的方法:

自定义函数过滤法
将以下函数代码放入/e/class/userfun.php文件中

函数代码如下,:

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简介字段了。

大模板网_建站模板源码下载_企业网站源码_PbootCMS模板免费分享平台,一个优质的源码资源平台!
大模板网_建站模板源码下载_企业网站源码_PbootCMS模板免费分享平台 » 帝国CMS截取内容简介并过滤特殊字符及空格