Ik heb een vreemd probleem. Ik wil dus d.m.v. PHP mijn weekly artist feed van last.fm op mijn site weergeven. Nu heb ik op internet een artikel gevonden wat dit doet alleen dan geeft het betreffende script maar 2 dingen weer.
Nu dacht ik het wel te begrijpen en heb ik wat aanpassingen gemaakt. Momenteel heb ik onderstaande code:
Alleen nu is het vreemde dat ik de volgende output krijg:
Ik heb mijn code 100 keer doorgelezen, maar zie gewoon niet wat ik fout doe. Misschien iemand die ziet waar ik nu de mist in ga?
Nu dacht ik het wel te begrijpen en heb ik wat aanpassingen gemaakt. Momenteel heb ik onderstaande code:
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
| <?php $xml_file = "http://ws.audioscrobbler.com/1.0/user/Maurice-k/weeklyartistchart.xml"; $xml_artist_name_key = "*WEEKLYARTISTCHART*ARTIST*NAME"; $xml_artist_play_key = "*WEEKLYARTISTCHART*ARTIST*PLAYCOUNT"; $xml_artist_url_key = "*WEEKLYARTISTCHART*ARTIST*URL"; $story_array = array(); $counter = 0; class xml_story{ var $name, $play, $url; } function startTag($parser, $data){ global $current_tag; $current_tag .= "*$data"; } function endTag($parser, $data){ global $current_tag; $tag_key = strrpos($current_tag, '*'); $current_tag = substr($current_tag, 0, $tag_key); } function contents($parser, $data){ global $current_tag, $xml_artist_name_key, $xml_artist_play_key, $xml_artist_url_key, $counter, $story_array; switch($current_tag){ case $xml_artist_name_key: $story_array[$counter] = new xml_story(); $story_array[$counter]->name = $data; break; case $xml_artist_play_key: $story_array[$counter]->playcount = $data; $counter++; break; case $xml_artist_url_key: $story_array[$counter]->url = $data; $counter++; break; } } $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startTag", "endTag"); xml_set_character_data_handler($xml_parser, "contents"); $fp = fopen($xml_file, "r") or die("Could not open file"); $data = fread($fp, 4096) or die("Could not read file"); if(!(xml_parse($xml_parser, $data))){ die("Error on line " . xml_get_current_line_number($xml_parser)); } xml_parser_free($xml_parser); fclose($fp); echo("<ol>\n"); for($x=0;$x<10;$x++){ echo("<li><a href=\"".$story_array[$x]->url."\" title=\"".$story_array[$x]->name." – Music at Last.fm\">".$story_array[$x]->name."</a> - ".$story_array[$x]->playcount."</li>\n"); } ?> </ol> |
Alleen nu is het vreemde dat ik de volgende output krijg:
HTML:
1
2
3
4
5
6
7
8
9
10
11
12
| <ol> <li><a href="" title="Juelz Santana – Music at Last.fm">Juelz Santana</a> - 50</li> <li><a href="http://www.last.fm/music/Juelz+Santana" title=" – Music at Last.fm"></a> - </li> <li><a href="" title="The Game – Music at Last.fm">The Game</a> - 38</li> <li><a href="http://www.last.fm/music/The+Game" title=" – Music at Last.fm"></a> - </li> <li><a href="" title="édéric Chopin – Music at Last.fm">édéric Chopin</a> - 34</li> <li><a href="http://www.last.fm/music/Fr%C3%A9d%C3%A9ric+Chopin" title=" – Music at Last.fm"></a> - </li> <li><a href="" title="Chamillionaire – Music at Last.fm">Chamillionaire</a> - 28</li> <li><a href="http://www.last.fm/music/Chamillionaire" title=" – Music at Last.fm"></a> - </li> <li><a href="" title="T.I. – Music at Last.fm">T.I.</a> - 27</li> <li><a href="http://www.last.fm/music/T.I." title=" – Music at Last.fm"></a> - </li> </ol> |
Ik heb mijn code 100 keer doorgelezen, maar zie gewoon niet wat ik fout doe. Misschien iemand die ziet waar ik nu de mist in ga?