<div>{dede:php}$row = $GLOBALS['dsql']->GetOne("select id from dede_archives where typeid=4 order by rand() LIMIT 1"); $row2 = $GLOBALS['dsql']->GetOne("select body from dede_addonarticle where aid=".$row['id']); $pattern='/key=(.*?)"/'; $arr = preg_match($pattern, $row2['body'],$mc); $str = $mc[1]; preg_replace("/\s/", "",$str); print_r('<iframe width="700" height="400" src="'.$str.'" frameborder="0" border="0" marginwidth="0" marginheight="0" scrolling="no" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true"></iframe>');{/dede:php} </div>
上图匹配一个网址如图key的部分:

若dede:php标签不管用,下图

模板引擎禁用标签中,去掉“php”即可;
------------------------------------------------------------
另:plus下模板中可直接写php代码,如下:

本文介绍了一种在DEDECMS中使用PHP代码随机选取并iframe嵌入文章内容的方法,通过正则表达式从随机选择的文章中匹配特定URL进行展示。
4217

被折叠的 条评论
为什么被折叠?



