Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php /*encoding:utf-8*/
- error_reporting(E_ALL);
- $dir = "adminpanel/";
- $recursive = true;
- $count = 0;
- dir_walk("fileprint", $dir, array("php"), $recursive, $dir);
- echo "processed: $count files";
- function fileprint($file)
- {
- global $count;
- $content = file_get_contents($file);
- if (strripos($content, "encoding:utf-8") === false)
- {
- $pi = strpos($content, "<?");
- if ($pi !== false)
- {
- file_put_contents($file.".bak", $content);
- $pi += strlen("<?");
- $content = iconv("ISO-8859-2", "UTF-8", $content);
- $content = substr($content, 0, $pi)." /*encoding:utf-8*/ ".substr($content, $pi);
- //echo $file."\n".$content."\n\n";
- file_put_contents($file, $content);
- $count ++;
- }
- }
- }
- function dir_walk($callback, $dir, $types = null, $recursive = false, $baseDir = '') {
- if ($dh = opendir($dir)) {
- while (($file = readdir($dh)) !== false) {
- if ($file === '.' || $file === '..') {
- continue;
- }
- if (is_file($dir . $file)) {
- if (is_array($types)) {
- if (!in_array(strtolower(pathinfo($dir . $file, PATHINFO_EXTENSION)), $types, true)) {
- continue;
- }
- }
- $callback($baseDir . $file);
- }elseif($recursive && is_dir($dir . $file)) {
- dir_walk($callback, $dir . $file . DIRECTORY_SEPARATOR, $types, $recursive, $baseDir . $file . DIRECTORY_SEPARATOR);
- }
- }
- closedir($dh);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement