2012-04-12 42 views
0

我有一個php腳本script1.php。我想將參數傳遞給script2.php並從script1.php執行它。 (script2.php輸出保存到一個文本文件,這是在script1.php使用)傳遞參數並執行另一個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(); 

?> 

如果我只是執行此它正常工作,但如果我包括在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 

也是,我沒有在服務器上爲外殼的執行權限。

回答

1

你可以簡單地包括script1.php

include 'script2.php'; 

您不必傳遞參數的script2.php,變量,存在include聲明將在SCRIPT2可用之前裏面的script2.php。 PHP一樣正常。

+0

請檢查我的編輯問題 – jacksparrow007 2012-04-12 12:59:50

0

爲了使用反引號來調用系統命令

<?php 
`script1.php any_command_line_options_goes_here`; 

//example 
`/usr/bin/php -i`; 

然後你就可以讀出的執行文件後,在你script1.php

+0

我想你誤解了這個問題。 – 2012-04-12 12:53:05

+0

找到我正在尋找的答案 '$ data = file_get_contents('http://domain.com/a.php?this=that&that=this');' – jacksparrow007 2012-04-12 13:22:41

+0

@BenEverard可能 – lexabug 2012-04-14 20:01:23

相關問題