Sam
Sam

Reputation: 349

calling a file inside another file in php

Is there a way in PHP to include or execute code from a separate file?

For example, if we have 2 files:

a.php which contains:

<?php echo "i'm a.php"; ?>

and b.php which contains:

<?php 
echo "i'm b.php";
// some code here to "execute" a.php so that it prints i'm a.php as the output.
?>

When b.php is run it should display:

i'm b.php
i'm a.php

Upvotes: 2

Views: 6910

Answers (2)

UncleMiF
UncleMiF

Reputation: 1171

just universal solution (but maybe denied by local PHP-server configuration):

echo file('http://your-remote-host/path/a.php');

or your a.php must provide some gate:

<? # a.php
function a_php_output()
{
return "i'm a.php";
}
?>

<? # b.php
echo "i'm b.php";
include('a.php');
echo a_php_output();
?>

Upvotes: 3

symcbean
symcbean

Reputation: 48357

 <?php 
 echo "i'm b.php";
 include('a.php');
 ?>

C.

Upvotes: 5

Related Questions