내 데이터 파일에서 특정 블록을 찾아 내고 그 중 일부를 대체하려고합니다. 그런 다음 대체 된 데이터로 모든 것을 새 파일에 넣습니다. 현재 코드는 다음과 같습니다.preg_replace within preg_match_all 문제
$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
의 자리에 있어야합니까?
감사합니다.