作者atomuu (小原子)
看板PHP
标题[请益] 如何parse这种格式?
时间Thu Nov 8 17:47:06 2012
我的格式长这样
{attr:value}
请问要怎麽从这个字串中parse出attr跟value呢?
preg_match('{([^:]+):([^:]+)}',"{attr:value}", $matches)的结果
会出来
$matches[0] = {attr:value}
$matches[1] = {attr
$matches[2] = value}
可是我觉得应该
$matches[1] = attr
$matches[2] = value
才对,真的很奇怪为什麽有左右括弧
感觉不难但是就是想不到好的解法~~
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.30.39
※ 编辑: atomuu 来自: 140.112.30.39 (11/08 17:52)
2F:→ knuckles:要改成 '/\{([^:]+):([^:]+)\}/' 11/08 18:08
3F:→ alpe:json_decode 11/09 00:10