我將文本區域發佈到我的php腳本中,然後爲文本區域的每一行執行一個循環,然後再次使用文本區域循環中的數據。然後我試圖爲每個數組設置一個數組,並在最後爲所有數組檢索一個數組。但是我的代碼是給我的錯誤:在兩個循環中設置數組
if (isset($_POST['submit'])) {
$entries = array();
$text = trim($_POST['facebookpage']);
$text = explode("\n", $text);
foreach ($text as $line) {
$data = $html2->find("table.profileInfoTable");
$text2 = trim($data[0]);
$text2 = explode("<tr>", $text2);
foreach ($text2 as $line) {
if (strpos($line, 'Location') !== false) {
$location = $line;
}
}
$data1 = $html2->find("table.profileInfoTable");
$text2 = trim($data1[0]);
$text2 = explode("<tr>", $text2);
foreach ($text2 as $line) {
if (strpos($line, 'Email') !== false) {
$email = $line;
}
}
$mainarray = array("Email" => $email, "Location" => $location);
array_push(($mainarray),$entries);
}
var_dump($entries);
}`
而且錯誤是:
Fatal error: Only variables can be passed by reference in /home2/statonme/public_html/scraper.php on line 61
感謝您的答覆,已使得它做點什麼但是在瀏覽器窗口僅僅是卡住加載了。我想這是在我嘗試寫入數組的時候做的。 – 2013-03-23 07:45:09
請轉到:http://simonstaton.co.uk/scraper.php並在http://www.facebook.com/MauiNuiBotanicalGardens中輸入表單然後單擊提交併查看它的作用 – 2013-03-23 07:47:36
@SimonStaton我相信會發生這種情況,因爲你在之前的代碼中有一個無限循環。如果內存服務,PHP首先解析整個腳本,以瞭解它必須做什麼,並提醒你明顯的錯誤......它不知道該怎麼做。你的代碼現在在語法上是正確的,但這並不意味着你的代碼是完美無瑕的。 – 2013-03-23 07:50:10