include 引用了一个文件(模板文件)。然后想把这个文件的结果存为字符串,这个能实现吗?比如<?php
include template('forumthree:block/index');
$str="<div> </div>";
?>include template('forumthree:block/index');输出的结果为
<ul>
<li>XXXX</li>
<li>XXXX</li>
</ul>
现在想把红色的输出转为字符串形式。
然后想实现这种需求:
$str="<div>".这里需要连上include引用的模板的字符串."</div>";
不知如何写呢?
假如这么写:
$str="<div>".include template('forumthree:block/index')."</div>";
显然是不行的
include template('forumthree:block/index');
$str="<div> </div>";
?>include template('forumthree:block/index');输出的结果为
<ul>
<li>XXXX</li>
<li>XXXX</li>
</ul>
现在想把红色的输出转为字符串形式。
然后想实现这种需求:
$str="<div>".这里需要连上include引用的模板的字符串."</div>";
不知如何写呢?
假如这么写:
$str="<div>".include template('forumthree:block/index')."</div>";
显然是不行的
解决方案 »
- PHP的array获取值操作的问题.
- 我的3年PHP生涯
- 今日下载,昨日下载,本周下载怎么实现
- 这个PHP类怎么没效果呢
- 免費好用的 PDF Library 大收集
- 高分求解php如何实现后台的命令调用?!
- 写文件大小问题,或运行网页大小?
- 用php可以调用mysql数据库里的多媒体文件不?我echo出的都是乱码,echo前面也加了header(),求高手帮忙解决!
- 难道这里就没有高人么?这个问题始终没人能解决
- 关于php的ZipArchive类打开压缩包后,乱码问题
- The given path is misformatted or contained invalid characters
- php实现文件下载时出现乱码
$str="<div>$s</div>";
Array ( [2] => [array index_forum_extra/'.$titems[fid].']';if(!empty($_G['setting']['pluginhooks']['index_forum_extra'][$titems[fid]])) echo $_G['setting']['pluginhooks']['index_forum_extra'][$titems[fid]];?>
直接输出了原形来了,我要的是这个原形出来的html结果。
<!--{hook/index_forum_extra $titems[fid]}-->
如果用$s = file_get_contents('forumthree:block/index');
势必输出其原形来,而它输出的html结构是
[array index_forum_extra/2]这种形式,这才是我要的。
你这里面是身内容?试试$s = file_get_contents(template('forumthree:block/index'));
$str="<div>$s</div>";
既然能include引入,那么用file_get_contents()也是能获取到的.请仔细检查并自行分析,可单独打印template()结果查看得到的是什么.我认为@fdipzone 方法没错.
include template('forumthree:block/index');
$tp = ob_get_clean();
$str="<div>$tp</div>";
你这里面是用php处理的吧,不是静态html改成这样就可以了。ob_start();// 开启缓冲区,放在文件最顶
ob_end_flush(); // 把缓冲区现有的数据先强制输出
ob_flush();
include template('forumthree:block/index'); // include 后会把内容输出到缓冲区
$data = ob_get_contents(); // 获取缓冲区内容,因为之前强制输出过,所以缓冲区内只有include template('forumthree:block/index'); 的数据
ob_clean(); // 清空缓冲区
$str = '<div>'.$data.'</div>';
echo $str;