【发布时间】:2017-08-29 08:08:28
【问题描述】:
我想在表达定义的每个单词周围加上引号。所有单词都必须以冒号结尾。
例如:
def1: "some explanation"
def2: "other explanation"
必须转化为
"def1": "some explanation"
"def2": "other explanation"
我如何在 PHP 中使用 preg_replace 编写这个?
我有这个:
preg_replace('/\b:/i', '"$0"', 'def1: "some explanation"')
但它只引用冒号,而不是单词:
key":" "value"
【问题讨论】:
-
如果有人帮助你,别忘了将答案标记为正确 :)
-
查看我的回答,它可能会帮助您替换所有出现的情况
标签: php json regex object-literal