How open php file from another php file?

I want to call a PHP file that starts like


I get:

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

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

asked May 15, 2010 at 17:41

It's trying to run it as a shell script, which interprets your

In b.php put:


Prints:

eric@dev ~ $ php a.php
onetwothree

answered May 15, 2010 at 17:50

3

exec is shelling to the operating system, and unless the OS has some special way of knowing how to execute a file, then it's going to default to treating it as a shell script or similar. In this case, it has no idea how to run your php file. If this script absolutely has to be executed from a shell, then either execute php passing the filename as a parameter, e.g

exec ['/usr/local/bin/php -f /opt/lampp/htdocs/.../name.php]'] ;

or use the punct at the top of your php script

#!/usr/local/bin/php

answered May 15, 2010 at 17:54

Mark BakerMark Baker

206k31 gold badges338 silver badges380 bronze badges

1

Sounds like you're trying to execute the PHP code directly in your shell. Your shell doesn't speak PHP, so it interprets your PHP code as though it's in your shell's native language, as though you had literally run

Chủ Đề