Php 如何在preg\u match\u all中将多个值组合在一起
嘿,朋友们,我对PHP中的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, "
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]之类的数字,此解决方案最好使用正则表达式+