T
T
tyoma_koder2021-07-17 13:42:37
PHP
tyoma_koder, 2021-07-17 13:42:37

Why doesn't preg_match_all work?

For string

$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 contains an empty array
preg_match_all('@(?<="name":).+?(?=",")@imu', $txt, $name);

I checked the regex at https://regex101.com/ , everything works

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2021-07-17
@tyoma_koder

everything works great
60f2c592225cf920291386.png60f2c5a241d3e844068233.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question