Fix: Reformatting Youtube Auto Generated Caption File

If you download auto-generated caption file from youtube and then use it in other platform like vimeo, you will see this auto-generated caption file doesn’t work. We can fix this by running a regular expression like this: $caption_raw = file_get_contents($file_path); $caption_formatted = preg_replace(‘/(<\d{2}:\d{2}:.*?(?:>)<c>)|(<\/c>)|(align:start position:\d+%)/’, ”, $caption_raw); $over_written = file_put_contents($file_path, $caption_formatted);  

PHP: Search for Files Inside Folder and Sub-Folder

To find all png files inside uploads directory we can use following code. This would search in all sub-directories as well. $Directory = new RecursiveDirectoryIterator(‘/wp-content/uploads/’); $Iterator = new RecursiveIteratorIterator($Directory); $Regex = new RegexIterator($Iterator, ‘/^.+\.png$/i’, RecursiveRegexIterator::GET_MATCH); foreach ($Regex as $file) { $file = $file[0]; }