0

Basically I want to run a PHP file from another PHP file to get the output as a string. I also want to be able to pass variables into it.

For example:

$result = get_output('./otherfile.php', $vars);

I have no idea how to do it. any help would be really appreciated.

0

2 Answers 2

0

Try reading this and file_get_contents

$contents = file_get_contents('http://www.stackoverflow.com/');
echo $contents;
Sign up to request clarification or add additional context in comments.

Comments

0

You have two files, 'included.php' and 'launch.php':

included.php

<?php echo $hello;

launch.php

$hello = 'hi';
ob_start();
include('included.php');
$returned = ob_get_contents();
ob_end_clean();

In '$returned' you have stored the results of the 'included.php' code (try to launch var_dump($returned));

As you can see, you can pass variables creating them before the inclusion of included.php. With ob_start you start to save the output of the page and then, with ob_get_contents, you put the result in a variable.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.