织梦Dedecms通过自定义标签源码远程读取调用远程文件
在管理后台,模板 下的 标签源码管理,新建标签源码,文件名为:readfile.lib.php
代码如下:
<?php
if(!defined('DEDEINC'))
{
exit("Request Error!");
}
function lib_readfile(&$ctag,&$refObj)
{
global $dsql,$envs;
//属性处理
$attlist="url|";
FillAttsDefault($ctag->CAttribute->Items,$attlist);
extract($ctag->CAttribute->Items, EXTR_SKIP);
if($url != '')
{
$contents = file_get_contents($url);
//如果出现中文乱码使用下面代码
//$contents = iconv(gb2312″, utf-8″,file_get_contents($url));
}
else{
$contents = '远程地址不能为空';
}
$revalue = $contents;
return $revalue;
}
?>
使用方法:
在模板里文件里,将下面代码放到你想放的位置上,
{dede:readfile url='需要读取的页面地址'}{/dede:readfile}
例如:
{dede:readfile url='http://www.queqi.net/DQ/Xinwen/2010/0530/9.html'}{/dede:readfile}
发表评论 取消回复