When I try this test script ..
$filenames = array_map('trim',file('WP_ro_files.txt',FILE_IGNORE_NEW_LINES| FILE_SKIP_EMPTY_LINES));
//Tweak your file searches for PCRE...
$files = array(
//Now filter your array.
$todelete = array_diff($filenames,preg_filter($files,$files,$filenames));
the dump returns all filenames. The preg_filter() function has the array $files defined as 2 parameters, the "pattern", and the "replace". Is that correct ?
I think the contents of $filenames is causing unexpected results. There are filenames like
whereas I only wanted to look for "plugins" or "themes" in the second part of the pathname, not anywhere.
edit: Also, the result of the preg_filter() has changed the values, such as