Good day. Trying to parse the text from the "script" tag and convert it to "JSON". So, the $ arSlider variable is perfectly converted to json, but $ arOffers is not converted, but the string is output. There are comments in the code. What am I doing wrong?
Sample value of $arOffers = {"1441":{"ARTIKUL":"01001","PROPS":[{"VALUE":"Клинок - Полированный","NAME":"Покрытие\\цвет клинка "},{"VALUE":"Рукоять - Эластрон","NAME":"Рукоятка"},{"VALUE":"Чехол - Натуральная кожа со вставкой из АБС пластика","NAME":"Чехол"}]},"1442":{"ARTIKUL":"01003","PROPS":[{"VALUE":"Клинок - Стоунвош черный","NAME":"Покрытие\\цвет клинка "},{"VALUE":"Рукоять - Эластрон","NAME":"Рукоятка"},{"VALUE":"Чехол - Натуральная кожа со вставкой из АБС пластика","NAME":"Чехол"}]}}
include('/inc/simple_html_dom.php');
$url = 'Already to nothing, the problem is solved!';
$html = file_get_html($url);
foreach ($html->find('script') as $el) {
if (stristr($el->outertext, "arSlider") !== false) {
$script = str_replace("'", '"', trim(stristr($el->outertext, "arSlider")));
$script = explode(" arOffers = ", $script);
$arSlider = str_replace("arSlider = ", "", $script[0]);
$arSlider = str_replace(";", "", $arSlider);
$arOffers = str_replace("; ", "", $script[1]);
$arOffers = str_replace("</script>", "", $arOffers); //Add
print_r(json_decode($arSlider));
print_r(json_decode($arOffers));
//It's working! )))
}
}
UPDATE
The problem showed me var_dump(json_encode($ arOffers));
The line did not show the closing tag </script>
Added replace and it worked! )))