L
L
lexstile2018-10-19 10:35:48
PHP
lexstile, 2018-10-19 10:35:48

What did I miss (Simple HTML DOM Parser)?

1. There is a file with urls. 2. I want to loop through the elements of the array (that is, through the URLs). That doesn't work.
$array = file(file.txt');

foreach($array as $url)
  {	
    if(!empty($url))
    {
      $html = _curl($url); // возвращает страницу плюс оборачивает результат в функцию str_get_html()
      echo $html; // должна вывестись первая страница из файла
      exit;
    }
  }

If I write the url directly, for example _curl('site.ru') - everything works.
This is how it works:
$array = file('file.txt');
  $html = _curl('site.ru/product/1/');
  echo $html->find('span.price-new',0)->plaintext; // выводит цену товара

If I get the urls from the file using the file() function , nothing works.
I tried this, it doesn't work either:
$array = file('file.txt');
  $html = _curl($array[0]);
  echo $html->find('span.price-new',0)->plaintext;

I can't understand why it only works if a direct url is specified, and not from a file.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nick Sdk, 2018-10-19
@lexstile

lexstile , do trim($array[0])
what you have when you "parse" a file with file(), line breaks can stay in your "url"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question