如何在preg_match _all中一起获取多个值

时间:2018-09-24 03:45:22

标签: php

嘿朋友,我在PHP中遇到preg_match_all问题

我有这样的输出

"offerId" : 104, 
"offerName" : "Abcd", 
"alertText" : null,
"payoutType" : "REGISTER", 
"payoutDetails" : [ 
    { "propertyName" : "REGISTER",
      "propertyValue" : "1.0",
      "offerId" : 105, 
      "alertText" : null,
      "payoutType" : "REGISTER",
      "offerName" : "Abcdeeee", 
      "payoutDetails" : [ 
          { "propertyName" : "REGISTER",
            "propertyValue" : "1.0",
            "offerId" : 106,
            "offerName" : "Abcde", 
            "alertText" : null,
            "payoutType" : "REGISTER",
            "payoutDetails" : [
                { "propertyName" : "REGISTER",
                  "propertyValue" : "1.0"

现在,我想根据商品ID 1比1保存此格式的值

offerid:-104 :offername-abcd:propertyValue:-1.0

我尝试过preg_match_all,但是它不能同时适用于所有值 以给定格式存储值的最佳方法是什么

1 个答案:

答案 0 :(得分:0)

输出不完整。看起来像JSON? 无论如何,删除多余的空格:

git clone whatever D:/dest

运行代码:https://3v4l.org/WHaon