开发者

calling a file inside another file in php

开发者 https://www.devze.com 2022-12-15 07:19 出处:网络
Is there a way in PHP to include or execute code from a separate file? For example, if we have 2 files:

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"; ?>开发者_StackOverflow;

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


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

C.


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();
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消