I am trying to create an array that should return some html as well of some other data through an ajax call. The thing is I need to include a php file that first has to build the HTML page, bue when I use a command like file_get_contents()
:
$array['nav'] = array(
1 => false
);
$array['content'] = array(
1 => file_get_contents('filename.php')
);
$array['stylesheets'] = array(
1 => 'admin'
);
It just returns all my php code as well in the array.. I have also tried to use include()
, but it automatically displays all the HTML before I can echo a json-encoded array, which won't work with my AJAX call. Any idea how to solve this?
Ex.
file_a.php
$array['nav'] = array(
1 => false
);
$array['content'] = array(
1 => file_get_contents('file_b.php')
);
$array['stylesheets'] = array(
1 => 'admin'
);
file_b.php
<div class="something">
<?php
foreach($data as $key => $value) {
echo 'This is a ' . $value . '\n';
}
?>
</div>
This code will make the $array['content'][1]
have the value <div class="something"> <?phpforeach($data as $key => $value) { echo 'This is a ' . $value . '\n'; } ?> </div>
instead of the actual HTML