更换分组图案我有,我想用PHP从字符串数组取代“Systems_x0020_Changed_IDs”值的JSON文件。 “39122”变成[39122],并且“39223,39244,39395”变成[39223,39244,39395]。我正在使用http://www.regexpal.com/来测试我的表情。表达式是:问题与PHP的正则表达式
"([(0-9)+((, *))]+)+"
这在PHP中产生了意想不到的结果。在我的JSON文件:
[{ "ID": 1050436, "Title": "THE SKY IS FALLING!!!!", "Application_x0020_ID": 242, "Systems_x0020_Changed": "Academic Planning System (APS),\"Documents planning and evaluation processes at UGA that support cont", "Systems_x0020_Changed_IDs": "39122", "Status": "New", "Modified": "2015-10-28T16:14:45.573-04:00", "Age": 40, "Description_x0020__x0028_Public_x0029_": "I'm chicken little and the SKY IS FALLING!", "Impact_x0020__x0028_Public_x0029_": "The world is going to end!", "Start_x0020_Time": "2015-10-28T00:00:00-04:00", "End_x0020_Time": "2015-10-30T00:00:00-04:00", "Hours": 12 }, { "ID": 1050740, "Title": "This is a Title", "Application_x0020_ID": 242, "Systems_x0020_Changed": "EITS Websites,\"EITS departmental web pages.\", GACRC Archival Storage,\"Archival Storage for Research Data\", VPS,\"Mainframe distributed printing system\"", "Systems_x0020_Changed_IDs": "39223, 39244, 39395", "Status": "New", "Modified": "2015-11-05T17:31:13.15-05:00", "Age": 32, "Description_x0020__x0028_Public_x0029_": "We will tell jokes to the clients", "Impact_x0020__x0028_Public_x0029_": "Everyone will notice the change.", "Start_x0020_Time": "2015-11-27T08:38:00-05:00", "End_x0020_Time": "2015-11-30T00:00:00-05:00", "Hours": 1 }]
在线路末端的几个逗号被替换括号[],使输出的样子:
[{ "ID": 1050436, "Title": "THE SKY IS FALLING!!!![,]Application_x0020_ID": 242, "Systems_x0020_Changed": "Academic Planning System (APS),\"Documents planning and evaluation processes at UGA that support cont[,]Systems_x0020_Changed_IDs": 39122, "Status": "New[,]Modified": "2015-10-28T16:14:45.573-04:00[,]Age": 40, "Description_x0020__x0028_Public_x0029_": "I'm chicken little and the SKY IS FALLING![,]Impact_x0020__x0028_Public_x0029_": "The world is going to end![,]Start_x0020_Time": "2015-10-28T00:00:00-04:00[,]End_x0020_Time": "2015-10-30T00:00:00-04:00[,]Hours": 12 }, { "ID": 1050740, "Title": "This is a Title[,]Application_x0020_ID": 242, "Systems_x0020_Changed": "EITS Websites,\"EITS departmental web pages.\", GACRC Archival Storage,\"Archival Storage for Research Data\", VPS,\"Mainframe distributed printing system\"[,]Systems_x0020_Changed_IDs": [39223, 39244, 39395], "Status": "New[,]Modified": "2015-11-05T17:31:13.15-05:00[,]Age": 32, "Description_x0020__x0028_Public_x0029_": "We will tell jokes to the clients[,]Impact_x0020__x0028_Public_x0029_": "Everyone will notice the change.[,]Start_x0020_Time": "2015-11-27T08:38:00-05:00[,]End_x0020_Time": "2015-11-30T00:00:00-05:00[,]Hours": 1 }]
我的问题是,我怎么能修改表达式所以PHP的行为就像regexpal.com一样,只有引号内的数字并忽略其余部分?
修改与正则表达式结构化数据像JSON是自找麻烦。我建议用'json_decode'将它读入适当的结构中,修改结构并用'json_encode'将其写回。 –