tyoma_koder
@tyoma_koder

Почему preg_match_all не работает?

Для строки
$txt = {"id":823,"prices":[{"quantity":{"from":null,"to":null},"base":{"value":34990,"display":"34 990 руб."},"discount":{"use":false,"percent":0,"value":34990,"display":"34 990 руб.","difference":"0"},"currency":null}],"available":true,"article":null,"quantity":{"value":25,"ratio":1,"measure":null,"trace":true,"zero":false},"sort":"1","measures":null,"name":"ВХОДНАЯ ДВЕРЬ АРГУС «ДА-92» ИДЕН","properties":[],"quickView":{"show":true,"template":"quick.view.2","parameters":{"IBLOCK_TYPE":"catalogs","IBLOCK_ID":13,"SECTION_URL":"\/catalog\/#SECTION_CODE_PATH#\/","DETAIL_URL":"\/catalog\/#SECTION_CODE_PATH#\/#ELEMENT_ID#\/","BASKET_URL":"\/personal\/basket\/","ACTION_VARIABLE":null,"PRODUCT_ID_VARIABLE":null,"SECTION_ID_VARIABLE":null,"PRODUCT_QUANTITY_VARIABLE":null,"PRODUCT_PROPS_VARIABLE":null,"CACHE_TYPE":"A","CACHE_TIME":"36000000","CACHE_GROUPS":"Y","SET_TITLE":"N","SET_LAST_MODIFIED":"N","MESSAGE_404":null,"SET_STATUS_404":"N","PRICE_CODE":["BASE",""],"USE_PRICE_COUNT":"Y","SHOW_PRICE_COUNT":1,"PRICE_VAT_INCLUDE":"Y","PRICE_VAT_SHOW_VALUE":"N","ADD_PROPERTIES_TO_BASKET":"Y","PARTIAL_PRODUCT_PROPERTIES":"N","LINK_IBLOCK_TYPE":null,"LINK_IBLOCK_ID":null,"LINK_PROPERTY_SID":null,"LINK_ELEMENTS_URL":null,"USE_MAIN_ELEMENT_SECTION":"Y","DISABLE_INIT_JS_IN_COMPONENT":"N","SET_VIEWED_IN_COMPONENT":"Y","HIDE_NOT_AVAILABLE_OFFERS":"N","PRODUCT_DISPLAY_MODE":"Y","PRODUCT_PROPERTIES":"","OFFER_TREE_PROPS":["OFFERS_SIZE"],"OFFERS_CART_PROPERTIES":"","OFFERS_FIELD_CODE":[],"OFFERS_PROPERTY_CODE":["OFFERS_SIZE"],"OFFERS_SORT_FIELD":"sort","OFFERS_SORT_ORDER":"asc","OFFERS_SORT_FIELD2":"id","OFFERS_SORT_ORDER2":"desc","CURRENCY_ID":"RUB","CONVERT_CURRENCY":"Y","USE_COMPARE":"Y","COMPARE_PATH":"\/catalog\/compare.php?action=#ACTION_CODE#","COMPARE_NAME":"compare","PROPERTY_OLD_PRICE_BASE":"","USE":"Y","DETAIL":"N","VIEW":"right","TEMPLATE":2,"ACTION":"buy","COUNTER_SHOW":"Y","DESCRIPTION_MODE":"preview","DESCRIPTION_SHOW":"Y","GALLERY_PANEL":"Y","GALLERY_PREVIEW":"Y","INFORMATION_PAYMENT":"Y","INFORMATION_SHIPMENT":"Y","LAZYLOAD_USE":"Y","MARKS_SHOW":"Y","PAYMENT_URL":"\/help\/buys\/payment\/","PROPERTY_CODE":["OLD_PRICE"],"PROPERTY_DESCRIPTION":"","PROPERTY_TEXT":"","QUANTITY_SHOW":"Y","SHIPMENT_URL":"\/help\/buys\/delivery\/","SLIDE_USE":"Y","TIMER_SHOW":"N","WEIGHT_SHOW":"Y","FORM_ID":"3","FORM_TEMPLATE":".default","FORM_PROPERTY_PRODUCT":"7","PROPERTY_MARKS_RECOMMEND":"RECOMMEND","PROPERTY_MARKS_NEW":"NEW","PROPERTY_MARKS_HIT":"HIT","PROPERTY_ORDER_USE":"ORDER_USE","CONSENT_URL":"\/company\/consent\/","LAZY_LOAD":"Y","VOTE_MODE":"rating","DELAY_USE":"Y","QUANTITY_MODE":"logic","QUANTITY_BOUNDS_FEW":null,"QUANTITY_BOUNDS_MANY":null,"VIDEO_IBLOCK_TYPE":"content","VIDEO_IBLOCK_ID":"31","VIDEO_PROPERTY_URL":"LINK","SERVICES_IBLOCK_TYPE":"catalogs","SERVICES_IBLOCK_ID":"16","REVIEWS_IBLOCK_TYPE":"catalogs","REVIEWS_IBLOCK_ID":"15","REVIEWS_PROPERTY_ELEMENT_ID":"ELEMENT_ID","REVIEWS_USE_CAPTCHA":"N","PROPERTY_ARTICLE":"ARTICLE","PROPERTY_BRAND":"BRAND","PROPERTY_PICTURES":"PICTURES","PROPERTY_SERVICES":"SERVICES","PROPERTY_DOCUMENTS":"DOCUMENTS","PROPERTY_ADDITIONAL":"ADDITIONAL","PROPERTY_ASSOCIATED":"ASSOCIATED","PROPERTY_RECOMMENDED":"RECOMMENDED","PROPERTY_VIDEO":"VIDEO","OFFERS_PROPERTY_ARTICLE":"ARTICLE","OFFERS_PROPERTY_PICTURES":"PICTURES","ELEMENT_ID":823,"ELEMENT_CODE":"vkhodnaya_dver_argus_da_92_iden","SECTION_ID":"65","SECTION_CODE":null}},"offers":[]}

$name содержит пустой масив
preg_match_all('@(?<="name":).+?(?=",")@imu', $txt, $name);

Проверял регулярку на https://regex101.com/, всё работает
  • Вопрос задан
  • 112 просмотров
Решения вопроса 3
ThunderCat
@ThunderCat Куратор тега PHP
{PHP, MySql, HTML, JS, CSS} developer
для тех кто в танке:
$txt = '{"id":823, ... "SECTION_ID":"65","SECTION_CODE":null}},"offers":[]}'; //НУЖНЫ КАВЫЧКИ И ТОЧКА С ЗАПЯТОЙ!
$arr = json_decode($txt, true);
Ответ написан
tyoma_koder
@tyoma_koder Автор вопроса
С добавлением htmlspecialchars_decode заработало
json_decode(htmlspecialchars_decode($txt), true)
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы