本文详细说明phpcmsV9程序调用dz帖子内容时候,可以用于cms和dz整合时,cms自己写sql吊用论坛数据的时候过滤掉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’;
即可!
发财猫:www.facaimao.com
萝苔网:www.luotai.com
还没有评论,来说两句吧...