'™',
'MileTruth™' => 'MileTruth™',
'MileTruth™' => 'MileTruth™',
'MileTruth™' => 'MileTruth™',
// Corrupted quotes and dashes (UTF-8 bytes misinterpreted as ISO-8859-1 and then saved as UTF-8)
'–' => '–',
'—' => '—',
'’' => '’',
'“' => '“',
'â€' => '”',
'…' => '…',
'•' => '•',
// Corrupted spaces and symbols
'©' => '©',
' ' => ' ', // Often  + nbsp
'Â' => '', // Lone  artifact
'ðŸ' => '', // Broken emoji
// Fix existing trade entities if needed
'™' => '™',
'™' => '™',
'™' => '™',
];
/**
* Recursively find all files with specific extensions.
*
* @param string $dir
* @param array $extensions
* @return array
*/
function get_all_files(string $dir, array $extensions): array {
$files = [];
$items = scandir($dir);
foreach ($items as $item) {
if ($item == '.' || $item == '..' || $item == '.git' || $item == 'non-used' || $item == 'fix_encoding.php') continue;
$path = $dir . DIRECTORY_SEPARATOR . $item;
if (is_dir($path)) {
$files = array_merge($files, get_all_files($path, $extensions));
} else {
$ext = pathinfo($path, PATHINFO_EXTENSION);
if (in_array($ext, $extensions)) {
$files[] = $path;
}
}
}
return $files;
}
$files = get_all_files($directory, $extensions);
echo "Processing " . count($files) . " files...\n";
foreach ($files as $file) {
$content = file_get_contents($file);
if ($content === false) continue;
$original_content = $content;
// Apply replacements multiple times to handle nested issues
$changed = true;
while ($changed) {
$old_content = $content;
foreach ($replacements as $search => $replace) {
$content = str_replace($search, $replace, $content);
}
if ($old_content === $content) {
$changed = false;
}
}
if ($content !== $original_content) {
file_put_contents($file, $content);
echo "Fixed: $file\n";
}
}
echo "Done.\n";