file1.php
<?php
$listMenu=array('Menu #1','Menu #2','Menu #3');
?>
<div class="wjNavButton"><a><?php echo($listMenu[0]); ?></a></div>
<div class="wjNavButton"><a><?php echo($listMenu[1]); ?></a></div>
<div class="wjNavButton"><a><?php echo($listMenu[2]); ?></a></div>
file2.php
$buff=include('file1.php');
$rest='[{sectionId:"LT", sectionType:"menu", sectionData="'.$buff.'"}]';
echo($rest);
result:
[{sectionId:"LT", sectionType:"menu", sectionData="1"}]
question:
- is this possible to put result of php page in variable?
- how i can result as output of file1.php and not sectionData="1"?
答案 0 :(得分:1)
file2.php
$buff=include('file1.php');
$rest='[{sectionId:"LT", sectionType:"menu", sectionData="'.$buff.'"}]';
echo($rest);
看起来你需要关于该字符串的结束报价。
答案 1 :(得分:1)
ob_start();
include 'file1.php';
$buff = ob_get_clean();
$data = array(array('sectionId' => 'LT', 'sectionType' => 'menu', 'sectionData' => $buff));
echo json_encode($data);
$buff = include
获取网页内容。想象一下include
复制并将一个文件的内容粘贴到另一个文件中。它没有返回任何东西。 (除非您以不同的方式构建包含文件,否则请阅读the documentation。)json_encode
确保语法正确并正确转义值。