-1
这是我的JSON文件 sample.json如何使用preg_replace替换JSON值?
{
"lbl_name":"Your name",
"dynamic_name":"Hi, {{ name 1 }}, {{ name 2 }} and {{ name 3 }}"
}
和
$content = file_get_contents(sample.json);
$translate = json_decode$content, true);
$replaceContent = preg_replace('/\{{[^)]*\}}/', '%s', $translate);
print_r($replaceContent);
我得到的结果
Array ([lbl_name] => Your name [dynamic_name] => Hi %s)
我想结果应该是
Array ([lbl_name] => Your name [dynamic_name] => Hi %s, %s and %s)
谢谢
让你的正则表达式不贪心:'*' - >'*?' – Rizier123