Skip to content

Instantly share code, notes, and snippets.

@chrisyue
Last active September 19, 2016 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisyue/c2fcf285ee3185a0b2e2bd4009e6ab45 to your computer and use it in GitHub Desktop.
Save chrisyue/c2fcf285ee3185a0b2e2bd4009e6ab45 to your computer and use it in GitHub Desktop.
通过正则递归搜索指定目录里的文件
<?php
foreach (new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator('.', FilesystemIterator::SKIP_DOTS)), '/\.m3u8$/') as $file) {
$name = $file->getBasename(sprintf('.%s', $file->getExtension()));
$content = file_get_contents($file->getRealPath());
$newContent = str_replace($name, urlencode($name), $content);
file_put_contents($file->getRealPath(), $newContent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment