从另一个php执行php文件 [英] Execute php file from another php

查看:111
本文介绍了从另一个php执行php文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想调用一个像这样开始的PHP文件

I want to call a PHP file that starts like

<?php
function connection () {
   //Statements
}

我是这样从PHP调用的:

I call from the PHP like this:

<?php
exec ('/opt/lampp/htdocs/stuff/name.php');
?>

我得到:

line1-> cannot open ?: No such file
line 3 //Connection: not found
line 4 Syntax errror: "("

为什么这不能正确执行name.php文件?

Why doesn't this correctly execute the name.php file?

推荐答案

它正在尝试将其作为shell脚本运行,该脚本将您的<?php令牌解释为bash,这是语法错误.只需使用include()或其朋友之一:

It's trying to run it as a shell script, which interprets your <?php token as bash, which is a syntax error. Just use include() or one of its friends:

例如,在a.php中放置:

<?php
print "one";
include 'b.php';
print "three";
?>

b.php中放置:

<?php
print "two";
?>

打印:

eric@dev ~ $ php a.php
onetwothree

这篇关于从另一个php执行php文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆