-
-7 19
-
这是一篇转来的文章,可以用于cms和dz整合时,cms自己写sql吊用论坛数据的时候过滤掉html标签的.
废话少说.贴方法吧
在phpcms整合discuz中数据源调用时message过滤html标签代码
首先要创建phpcms中php文件及其对应的模板文件
然后使用数据源进行调用时,模板中的示例代码如下: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代码- <?php
- function clearHtml($content)
- {
- $content=preg_replace(‘/\[[^\[\]]{1,}\]/’,”,$content);
- return $content;
- }
- ?>
将此内容放入include的新建clear.php中
然后在你的php文件中加入
PHP代码- require dirname(__FILE__).’/include/clear.php’;
即可!
本文来源于php爱好者:php教程 —http://www.phplover.cn/
原文地址:http://www.phplover.cn/post/phpcms-sghujudiaoyondz-guolu-html.html
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
- 评论(0)
发表评论 TrackBack