Skip to content

Instantly share code, notes, and snippets.

@banyan
Created April 8, 2010 08:32
Show Gist options
  • Select an option

  • Save banyan/359904 to your computer and use it in GitHub Desktop.

Select an option

Save banyan/359904 to your computer and use it in GitHub Desktop.
<?php
// 再帰的に置換をする
$baseDir = './hoge';
foreach (glob($baseDir . '/*/*.txt') as $fileName) {
copy($fileName, $fileName . '.tmp');
$string = file_get_contents($fileName . '.tmp');
$pattern = '/ip4:/';
$replacement = 'ip4\\\072';
$string = preg_replace($pattern, $replacement, $string);
file_put_contents($fileName . '.tmp', $string);
rename($fileName . '.tmp', $fileName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment