how to store output html to an var in php ?
how to set $a = require(xx.php)?
the xx.php outputs html , i want to store this html to a var , how to do?
please see my codes bellow:
a.php codes:
<?php
// a.php
echo 'hello world';
?>
b.php
<pre>
<?php
ob_start();
$a=require('a.php');
ob_clean();
echo $a; // get '1' but not 'hello world'
// can not post , why?
// can not post , why?
// can not post , why?
// can not post , why?
// can not post , why?
// can not post , why?
?>
The result of the "require" is not what you want. Try:
ob_start();
require('a.php');
$a = ob_get_clean();
echo $a;
You're after ob_get_clean()
:
$a = ob_get_clean();
You could also use shell_exec
<?php
$out = shell_exec("php -s $File");
?>
Hi according to your case you want output of any PHP page which you want to use in your current page in that case you need to use CURL in PHP
$ch = curl_init('a.php');
$htmlResponse = curl_exec($ch);
curl_close($ch);
echo $htmlResponse ;
die;
finally, I got the answer.
<?php
ob_start();
require('a.php');
$a=ob_get_clean();
echo $a; // get '1' but not 'hello world'
?>