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
|
<?php
class convertCRLF {
public function __construct() {
$this->countfiles = 0;
$this->count = 0;
$this->ext = array (
'php',
'sh',
'ini',
'png',
'xml',
'ini',
'html',
'js',
'css',
'txt'
);
$this->returnlist = array ();
}
private function trim_CR_ContentFile($file) {
$datas = str_replace("\r", '', file_get_contents($file));
$fp = fopen($file, "wb+");
fwrite($fp, $datas);
fclose($fp);
}
private function getExtension($string) {
$getExtension = explode(".", $string);
return $getExtension[sizeof(explode(".", $string)) - 1];
}
public function viewtree($path = ".") {
$files = glob($path . '/*');
foreach ($files as $value) {
if (is_dir($value)) {
self :: viewtree($value);
} else {
if (in_array(strtolower(self :: getExtension($value)), $this->ext)) {
$this->count++;
$buffer = file_get_contents($value);
if (preg_match('['.chr(13).']', $buffer)) {
$this->returnlist[] = $value;
$this->countfiles++;
self :: trim_CR_ContentFile($value);
}
}
}
}
}
public function __toString() {
$return = $this->count .
' fichiers de type ' . implode(', ', $this->ext) .
'<br />' .
($this->countfiles != 0 ? $this->countfiles . ' trouvé' .
($this->countfiles > 1 ? 's' : false) .
'.' : 'Aucun CRLF trouvé.');
foreach ($this->returnlist as $value) {
$return .= '<br />' . $value . ' converti';
}
return $return;
}
}
$getfiles = new convertCRLF();
$getfiles->viewtree();
echo $getfiles;
?> |
Partager