phpcms数据源调用dz message过滤html标签

phpcms整合discuz中数据源调用时message过滤html标签代码
首先要创建phpcms中php文件及其对应的模板文件
然后使用数据源进行调用时,模板中的示例代码如下:
{get dbsource=”bbs” sql=”SELECT a.tid,a.subject, b.attachment,c.message  FROM `cdb_threads` a, `cdb_attachments` b,`cdb_posts` c WHERE a.tid = b.tid and a.tid=c.tid AND a.fid=21and a.typeid=101 GROUP BY b.tid ORDER BY a.dateline DESC  LIMIT 0,3″}
<a href=”bbs/viewthread.php?tid={$r[tid]}” target=”_blank”>·{str_cut($r[subject], 26,”)}</a>
<a href=”bbs/viewthread.php?tid={$r[tid]}” target=”_blank”><img src=”bbs/attachments/{$r[attachment]}” width=100></a>
{str_cut(clearhtml($r[message]),50,”)}
{/get}
上面显示红色的即为过滤掉的信息!
然后要再php文件中添加调用一个函数clearhtml
此函数的内容为:
<?php
function clearHtml($content)
{
$content=preg_replace(‘/\[[^\[\]]{1,}\]/’,”,$content);
 return $content;
}
?>
将此内容放入include的新建clear.php中
然后在你的php文件中加入
require dirname(__FILE__).’/include/clear.php’;
即可!


本站文章欢迎转载。转载请注明:转载自迷失曾经谢谢!
原文链接地址:phpcms数据源调用dz message过滤html标签 Tags: , , , ,

热门网购