帝国CMS常用的过滤特殊字符及空格方法汇总

微信扫一扫,分享到朋友圈

帝国CMS常用的过滤特殊字符及空格方法汇总
收藏 00

帝国cms内容页模板的描述标签,是直接输出内容标题,这个在seo优化当中还是有一定影响的,新闻在发布时会自动生成smalltext简介字段,但我们如果直接在页面上输出简介字段,经常会带有特殊字符或者带有换行,这个也是非常不好的。

方法1

代码如下:

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'])?>

方法2

打开文件e/class/connect.php

找到函数

sub($string,$start=0,$length,$mode=false,$dot='')

将其中的代码

$string = str_replace(array('&nbsp;','&amp;','&quot;','&lt;','&gt;','&#039;'), array(' ','&','"','<','>',"'"), $string);

替换成:

$string = str_replace(array('&nbsp;','&amp;','&quot;','&lt;','&gt;','&#039;','&ldquo;','&rdquo;'), array(' ','&','"','<','>',"'",'"','"'), $string);

 

一个热爱互联网的咸鱼
上一篇

帝国cms循环调用中如何使用数字编号递增的方法

下一篇

快速查站外死链工具(网站改版必备神器)

你也可能喜欢

发表评论

您的电子邮件地址不会被公开。 必填项已用 * 标注

提示:点击验证后方可评论!

插入图片

热门

    抱歉,30天内未发布文章!
返回顶部