I have a php script script1.php. I want to pass arguments to script2.php and execute it from script1.php. (script2.php saves the output to a text file which is used in script1.php)
我有一个php脚本script1.php。我想将参数传递给script2.php并从script1.php执行它。 (script2.php将输出保存到script1.php中使用的文本文件中)
Edit:
编辑:
This is my script2.php
这是我的script2.php
require_once('showtimes/simple_html_dom/simple_html_dom.php');
$html = new simple_html_dom();
//$requested4=$_GET['place'];
$html->load_file('http://www.google.com/movies?near=${requested4}&hl=en');
ob_start();
$muv='<pre>';
foreach($html->find('#movie_results .theater') as $div) {
// print theater and address info
$muv=$muv."Theatre: ".$div->find('h2 a',0)->innertext."\n";
$muv=$muv."Address: ". $div->find('.info',0)->innertext."\n";
// print all the movies with showtimes
foreach($div->find('.movie') as $movie) {
$muv=$muv."\tMovie: ".$movie->find('.name a',0)->innertext.'<br />';
$muv=$muv."\tTime: ".$movie->find('.times',0)->innertext.'<br />';
}
$muv=$muv. "\n\n";
}
$muv=$muv."</pre>";
//ob_get_contents();
ob_end_clean();
echo $muv;
file_put_contents('textfiles/file.txt', $muv);
$html->clear();
?>
If I just execute this it works normally, but if I include it in script1.php i get this error
如果我只是执行它,它正常工作,但如果我将它包含在script1.php中,我会收到此错误
Fatal error: Call to a member function find() on a non-object in /home/anandheg/public_html/anandghegde.in/se/showtimes/simple_html_dom/simple_html_dom.php on line 879
also, I don't have permissions on the server for shell executions.
另外,我没有在服务器上执行shell执行的权限。
2 个解决方案
#1
1
You can simply include the script2.php inside the script1.php
您可以在script1.php中包含script2.php
include 'script2.php';
You don't have to pass the parameter in the script2.php
, variables which exists before the include
statement will be available in script2.php as normal.
您不必在script2.php中传递参数,在include语句之前存在的变量将在script2.php中正常使用。
#2
0
Use backticks in order to call system command
使用反引号来调用系统命令
<?php
`script1.php any_command_line_options_goes_here`;
//example
`/usr/bin/php -i`;
Then you can read file after execution in you script1.php
然后你可以在script1.php中执行后读取文件
#1
1
You can simply include the script2.php inside the script1.php
您可以在script1.php中包含script2.php
include 'script2.php';
You don't have to pass the parameter in the script2.php
, variables which exists before the include
statement will be available in script2.php as normal.
您不必在script2.php中传递参数,在include语句之前存在的变量将在script2.php中正常使用。
#2
0
Use backticks in order to call system command
使用反引号来调用系统命令
<?php
`script1.php any_command_line_options_goes_here`;
//example
`/usr/bin/php -i`;
Then you can read file after execution in you script1.php
然后你可以在script1.php中执行后读取文件