1

When I do one website at once it works just fine but when I do more at a time I get the following error:

Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Host is onbekend. in C:\xampp\htdocs\blabla\simple_html_dom.php on line 76

Warning: file_get_contents(https://www.google.nl ): failed to open stream: php_network_getaddresses: getaddrinfo failed: Host is onbekend. in C:\xampp\htdocs\blabla\simple_html_dom.php on line 76

Fatal error: Call to a member function find() on a non-object in C:\xampp\htdocs\blabla\backend.php on line 21

This is my image scraper:

<?php
    if (isset($_POST["submit"])) {
        $notes = explode("\n", $_POST['linkjes']);

        foreach ($notes as $link) {
            x($link);
        }
    }
    else
    {
        echo "je hoort hier niet";
    }


    function x($link){

    $file = 'images.txt';
    $current = file_get_contents($file);
    include_once 'simple_html_dom.php';

    $html = file_get_html($link);

    foreach($html->find('img') as $element)

        if (strpos($element->src,'.png') !== false) 
        {
            $current .= $element->src."\n";
            file_put_contents($file, $current);
         } 
         else if (strpos($element->src,'.jpg') !== false) 
         {
            $current .= $element->src."\n";
            file_put_contents($file, $current);
         } 
         else if (strpos($element->src,'.gif') !== false) 
         {
                $current .= $element->src."\n";
            file_put_contents($file, $current);
         }
         else if (strpos($element->src,'.ico') !== false) 
         {
                $current .= $element->src."\n";
            file_put_contents($file, $current);
         }
         else if (strpos($element->src,'.jpeg') !== false) 
         {
                $current .= $element->src."\n";
            file_put_contents($file, $current);
         }

    $lines = file($file);
    $lines = array_unique($lines);
    file_put_contents($file, implode($lines));

    }
    ?>
AlexG
  • 5,649
  • 6
  • 26
  • 43
  • `simple_html_dom.php` - I suppose this is 3rd party library. To answer your question we should see the source code of this library, due to the fact that we do not know the versions of library you use – Ans Feb 09 '17 at 09:22
  • did you check for similar issues with that error? If not, please do. If you did, please add how that didn't help, e.g. : http://stackoverflow.com/questions/20064372/file-get-contents-php-network-getaddresses-getaddrinfo-failed-name-or-servi – Nanne Feb 09 '17 at 09:51
  • This appears to be unrelated to PHP (or arrays). According to Google Translator, "onbekend" is a Dutch word that means "unknown". Does your server have full internet connectivity? – Álvaro González Feb 09 '17 at 09:57
  • http://simplehtmldom.sourceforge.net/ this is the source of simple_html_dom.php – Calvin Janson Feb 09 '17 at 15:37

0 Answers0