【发布时间】:2016-01-07 13:59:51
【问题描述】:
有这样的字符串:
$str = "dateto:'2015-10-07 15:05' xxxx datefrom:'2015-10-09 15:05' yyyy asdf"
想要的结果是:
[0] => Array (
[0] => dateto:'2015-10-07 15:05'
[1] => xxxx
[2] => datefrom:'2015-10-09 15:05'
[3] => yyyy
[4] => asdf
)
我得到了什么:
preg_match_all("/\'(?:[^()]|(?R))+\'|'[^']*'|[^(),\s]+/", $str, $m);
是:
[0] => Array (
[0] => dateto:'2015-10-07
[1] => 15:05'
[2] => xxxx
[3] => datefrom:'2015-10-09
[4] => 15:05'
[5] => yyyy
[6] => asdf
)
还尝试使用preg_split("/[\s]+/", $str),但如果值在引号之间,则不知道如何转义。谁能告诉我如何,也请解释正则表达式。谢谢!
【问题讨论】:
标签: php regex preg-match preg-match-all preg-split