G
G
Good Samaritan2018-02-12 10:49:59
PHP
Good Samaritan, 2018-02-12 10:49:59

I don't understand why the code is not working?

Getting the contents of the head tag using code

<?
$html = file_get_html('http://site.ru/');
foreach ($html->find("head") as $elements) {
    $head = $elements;
}
echo $head;
?>

the code obtained with this does not display some elements, but if you manually copy the contents of the head tag from the site that I'm parsing and paste into my site, then everything works. Why is this happening? I checked that the resulting code using the parser is absolutely identical to the source code of the site that I am parsing.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Sklyarov, 2018-02-12
@0example

Because you're redefining $head every time, you need to add a dot before "equals". So with each iteration, you will add new data to the end

<?
$html = file_get_html('http://site.ru/');
foreach ($html->find("head") as $elements) {
    $head .= $elements;
}
echo $head;
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question