Answer the question
In order to leave comments, you need to log in
The encoding flies when parsing + the regular expression catches one result. Why?
Good afternoon. I decided to parse Eldorado, and in particular the prices of laptops. To begin with, I want to display all the prices of laptops, and then the products themselves (display only their picture, name, price, operating system)
There are several problems:
1. The site encoding flies
Code:
<?php
function get_content($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($ch);
curl_close($ch);
return iconv('UTF-8', 'Windows-1251//TRANSLIT//IGNORE', $res);
}
$file = get_content('https://www.eldorado.ru/cat/4005/');
//echo $file;
$pattern = '#<span class="discountPrice itemPrice">.+?<span class="rub">.+?</span></span>#s';
preg_match($pattern, $file, $matches);
print_r($matches);
?>
<span class="discountPrice itemPrice">29 990<span class="rub"> .</span></span>
#<span class="discountPrice itemPrice">.+?<span class="rub">.+?</span></span>#s
, and for some reason throws only one result. Answer the question
In order to leave comments, you need to log in
1) the meaning of this action? 'UTF-8 -> 'Windows-1251 megafrugal WPS, no room for bytes? do everything in utf8, including the base
2) why not php.net/manual/en/function.preg-match-all.php
3) imagine as if by a browser - you download everything, parse, select
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question