0

我将一个文本区域发布到我的 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
4

2 回答 2

1

Usually, the error messages of PHP give you a very good idea of what's wrong with your script.

I don't know where 'Line 61' in your script is, but I believe that if you put anything into brackets, it is considered an 'equation'...meaning that ($main_array) is not a variable...and you can't change an equation. You can only change variables.

Try removing the brackets around $main_array in array_push(($mainarray),$entries); (making it: array_push($mainarray, $entries);) and come back with results please.

于 2013-03-23T07:42:46.317 回答
1

我认为你有array_push倒退的论据。您要添加的数组应该是第一个参数,其余参数是要添加的元素。所以应该是:

array_push($entries, $mainarray);

或者,更简单地说:

$entries[] = array("Email" => $email, "Location" => $location);
于 2013-03-23T08:01:18.937 回答