-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