Hello,

J'essaye de "parser" ma librairie iTunes (que j'ai copiée dans le même dossier) avec le code suivant :

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
 
<?php
function cmp ($a, $b) {
	$sort = !empty($_GET["sort_by"]) ? $_GET["sort_by"] : "Artist";
	return strcmp($a[$sort], $b[$sort]);
}
usort($songs, "cmp");
 
function array_to_table($array, $printable) {
	//expects multi-dimensional array, all with the same keys
	$first_time=TRUE;
	$str = "<table border='1'>\n";
	$str .= "<tr>\n";
	foreach($array as $elem_key => $element) {
			if($first_time) {
				$header_items=array_keys($element);
					foreach($header_items as $header) {
						if(in_array($header, $printable)) {
							$str .= "<th><a href='" . $_SERVER["PHP_SELF"]
								. "?sort_by=" . urlencode($header) . "'>" . $header
								. "</a></th>\n";
						}
					}
				$str .= "</tr>\n";
				$first_time=FALSE;
			}
			$str .= "<tr>\n";
			foreach($element as $k => $v) {
				if(in_array($k, $printable)) {
					$str .= "<td>" . $v . "</td>\n";
				}
			}
			$str .= "</tr>\n";
	}
	$str .= "</table>";
	return $str;
}
$printable= array("Name", "Artist", "Album", "Size");
echo array_to_table($songs, $printable);
?>
Pour tout résultats j'ai

Warning: usort() [function.usort.html]: The argument should be an array in /Library/WebServer/Documents/XML_parsing/itunes/dom_parse_itunes.php on line 4

Warning: Invalid argument supplied for foreach() in /Library/WebServer/Documents/XML_parsing/itunes/dom_parse_itunes.php on line 9
et un écran blanc dessous...

Relu le code 10 fois, rien.

Merci.