Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在preg\u match\u all中将多个值组合在一起_Php - Fatal编程技术网

Php 如何在preg\u match\u all中将多个值组合在一起

Php 如何在preg\u match\u all中将多个值组合在一起,php,Php,嘿,朋友们,我对PHP中的preg\u match\u all有问题 我有这样的输出 "offerId" : 104, "offerName" : "Abcd", "alertText" : null, "payoutType" : "REGISTER", "payoutDetails" : [ { "propertyName" : "REGISTER", "propertyValue" : "1.0", "offerId" : 105, "

嘿,朋友们,我对PHP中的
preg\u match\u 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 x 1以这种格式保存值

offerid:-104 :offername-abcd:propertyValue:-1.0
我尝试了
preg\u match\u all
,但它不能同时处理所有值
以给定格式存储值的最佳方法是什么?输出不完整。看起来像JSON? 无论如何,如果删除了多余的空间:

$regex= "/\"offerId\" : (.*?), \"offerName\" : \"(.*?)\"/ms";

$subject='
"offerId" : 104, 
"offerName" : "Abcd", 
"alertText" : null,
"payoutType" : "REGISTER", 
"payoutDetails" : [ 
    { "propertyName" : "REGISTER",
      "propertyValue" : "1.0",
      "offerId" : 105, 
      "offerName" : "Abcdeeee",
      "alertText" : null,
      "payoutType" : "REGISTER", 
      "payoutDetails" : [ 
          { "propertyName" : "REGISTER",
            "propertyValue" : "1.0",
            "offerId" : 106,
            "offerName" : "Abcde", 
            "alertText" : null,
            "payoutType" : "REGISTER",
            "payoutDetails" : [
                { "propertyName" : "REGISTER",
                  "propertyValue" : "1.0"
                  ';
$subject = preg_replace('/\s+/', ' ', $subject);

preg_match_all($regex, $subject, $matches);

print_r( $matches);

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

您的输出不完整。。。请发布完整的输出(或至少是一个可用的子集),并按照我在编辑中所做的那样对其进行格式化。对于[0-9]之类的数字,此解决方案最好使用正则表达式+