Reputation: 1328
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)
Edit:
This is my 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
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.
Upvotes: 0
Views: 5521
Reputation: 316
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
Upvotes: 1
Reputation: 86366
You can simply include the script2.php inside the script1.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.
Upvotes: 1