帝国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简介字段了。
- 最新文章
-
- phpcms v9无法更新url
- phpcms注册会员操作失败
- phpcms怎么修改模板
- phpcms添加内容报500错误的原因及解决方法
- linux服务器下phpcms提示hash数据验证失败的解决方法
- phpcms与phpsso通信失败的解决方法
- phpcms上传图片提示服务器安全认证错误的原因及解决方法
- phpcms v9更新栏目缓存失败的原因及解决方法
- phpcms v9后台登录提示验证码错误
- phpcms可以做什么?
- phpcms v9安装失败
- phpcms会员登录失败
- phpcms前台js获取不到cookie用户信息
- phpcms控制器不存在
- phpcms v9 php7可以运行吗
- phpcms js乱码怎么解决
- phpcms提示服务器安全认证错误
- phpcms php.ini在哪里
- phpcms phpsso验证码错误
- phpcms v9参数传递错误
- 热门文章
- 热门tag
- 随机tag