我試圖在我的數據文件中找到一些特定的塊並替換它們中的某些內容。之後,整個事情(與替換的數據)到一個新的文件。我此刻的代碼如下所示:preg_match_all內preg_replace問題
$content = file_get_contents('file.ext', true);
//find certain pattern blocks first
preg_match_all('/regexp/su', $content, $matches);
foreach ($matches[0] as $match) {
//replace data inside of those blocks
preg_replace('/regexp2/su', 'replacement', $match);
}
file_put_contents('new_file.ext', return_whole_thing?);
現在的問題是,我不知道該怎麼return_whole_thing。基本上,file.ext和new_file.ext幾乎與被替換的數據相同。 任何建議return_whole_thing
應該在什麼位置?
謝謝!