-
Notifications
You must be signed in to change notification settings - Fork 0
/
fix_utf.php
78 lines (57 loc) · 1.28 KB
/
fix_utf.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
header('Content-Type: text/plain;charset=UTF-8');
/*
This file gets gemoved in the final release.
*/
define('ROOT', dirname(__FILE__));
function scandir_r($dir, $callback) {
if (!is_callable($callback)) return false;
$dirHandle = opendir($dir);
if ($dirHandle == false) return false;
while (($file = readdir($dirHandle)) != false) {
if (substr($file, 0, 1) == '.') continue;
$ext = explode('.', $file);
$ext = strtolower(end($ext));
$path = $dir.'/'.$file;
if (is_file($path)) {
$callback($file, $path, $ext);
} else {
scandir_r($path, $callback);
}
}
}
scandir_r(ROOT, function($file, $path, $ext) {
if ($ext == 'php' || $ext == 'html') {
if ($file == 'fix_utf.php') {
echo 'skipped fix_utf.php'.PHP_EOL.PHP_EOL;
return;
}
echo 'got file '.$file.' -> '.$path.PHP_EOL;
$content = file_get_contents($path);
echo mb_strlen($content).' bytes read'.PHP_EOL.PHP_EOL;
$content = str_replace(
array(
'ü',
'ö',
'ä',
'Ü',
'Ö',
'Ä'
),
array(
'ü',
'ö',
'ä',
'Ü',
'Ö',
'Ä'
), $content);
if (file_put_contents($path, $content, LOCK_EX) != false) {
echo mb_strlen($content).' bytes wrote';
} else {
echo 'ERROR WRITING FILE';
}
echo PHP_EOL.PHP_EOL;
}
});
?>