bonjour,
je travaille sous un systeme linux, et actuellement j'ai un problème avec un dossier contenant plusieurs fichiers copiés a partir d'un systeme windows, et donc ces fichiers portent le caractere "\r" sur leur en-tete. et donc il m'est impossible d'executer ces genre de fichier sur ma plateforme linux.
j'ai telecharger sur le net le script, ci-dessous, permettant de localiser les fichiers portant ce caractère et ensuite de le supprimer. malheureusement en executant le script, j'ai bien le message disant que le fichier a été converti, mais quand je verifie je me rend compte que le caractere "\r" s'y trouve encore.
quelqu'un ici pourrait-il jeter un coup d'oeil a ce script et me dire a quel niveau ça ne marche pas ? merci d'avance pour toute contribution.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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;
?>