Reputation: 45
I wish to call a local PHP page with PHP with the server side code already executed.
For instance, if I have a page with the following content:
Hello, this is <?php $name="John"; echo $name ?>
I wish to have a get command such as file_get_contents(local_php_page) or fopen(handle) return:
Hello, this is John
Rather than
Hello, this is <?php $name="John"; echo $name ?>
What's the best way to do this?
Upvotes: 2
Views: 174
Reputation: 15464
Need to call http url instead of path
$url="http://".$_SERVER['HTTP_HOST']."/yourpath/";
$str=file_get_contents($url."/yourfile.php");
echo $str;
Upvotes: 0
Reputation: 33439
If you have allow_url_fopen in your server, you might use fopen with an url.
Upvotes: 0
Reputation: 352
As you've already mentioned you can use file_get_contents to send a get request to any http url. You have to make sure, that allow_url_fopen is enabled. Of course your webserver has to be configured to handle php requests correctly
<?php
$requestUrl = 'http://localhost/your_file.php';
$content = file_get_contents($requestUrl);
var_dump($content);
Upvotes: 0
Reputation: 544
Output Buffering should be able to do that for you:
ob_start();
include 'myfile.php';
$xhtml = ob_get_clean();
You could also get the output of your include, eg:
$xhtml = include 'myfile.php';
For more on this, check out The PHP Manual
Upvotes: 1