2012-03-30 122 views
0

我想運行這個PHP腳本,我從書中的webbots,蜘蛛和屏幕抓取。從書中使用命令行運行PHP腳本

$target = "http://www.WebbotsSpidersScreenScrapers.com/hello_world.html"; 
$file_handle = fopen($target, "r"); 

# Fetch the file 
while(!feof($file_handle)) 
    echo fgets($file_handle, 4096); 
fclose($file_handle); 

我正在使用php first.php命令,它所做的就是將文件連接回給我。

+0

所以你不要看到輸出?你能詳細說明你遇到的問題嗎? – JohnP 2012-03-30 16:02:42

+0

我看到的只是它自己的實際腳本。就好像我在打字貓first.php – Sean 2012-03-30 16:05:04

+1

只是爲了確認,但你有'<?php'在右上角? – JohnP 2012-03-30 16:06:31

回答

1

你的完整劇本,應該是這樣的

<?php //<- opening tag for PHP 

$target = "http://www.WebbotsSpidersScreenScrapers.com/hello_world.html"; 
$file_handle = fopen($target, "r"); 

# Fetch the file 
while(!feof($file_handle)) { 
    echo fgets($file_handle, 4096); 
} 
fclose($file_handle); 
+0

旁註:這個例子是正確的,因爲很多人不知道如果在腳本結尾處不需要關閉'?>'標記。 – Cranio 2012-06-22 10:15:55