R
R
rasl892020-04-30 11:45:15
PHP
rasl89, 2020-04-30 11:45:15

Why doesn't iterate over references in foreach php?

Help, array enumeration not working.

There is an array with links:
$ssil12

The task is to connect the script for processing one link (parser),

iterate through the array with links, executing the script for each link:

foreach ($ssil12 as $https) {
        perebor($https);
    }


Function (in previously included file):
function perebor ($https='') {
 //обрабатывает ссылку, вносит в бд спарсенные строки
}


In the body of the function, the parser begins with: maybe links are not passed to it one by one?
$html = str_get_html($https); //получаем объек

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PQR, 2020-05-06
@PQR

If I correctly understood the condition of the problem, then the array $ssil12 contains links (in the sense of the url of the pages that need to be processed).
Further in the loop, you iterate over this array and eventually pass each individual link to the function call. str_get_html($https);
But judging by the documentation ( https://simplehtmldom.sourceforge.io/manual.htm) , it takes not a link as input , the html code of the page. Thus, you forgot to download the page itself from the link, for example, like this:

$content = file_get_contents($https)
$domObject = str_get_html($content);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question