вывести из xml посредством php

Discussion in 'PHP' started by comeoff, 11 Feb 2010.

  1. comeoff

    comeoff New Member

    Joined:
    10 Mar 2008
    Messages:
    89
    Likes Received:
    3
    Reputations:
    0
    Всем привет. есть экспорт файл медиатеки айтюнса, нужно вывести из него на страницу только название аудиофайлов name.mp3

    структура файла такая

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    	<key>Major Version</key><integer>1</integer>
    	<key>Minor Version</key><integer>1</integer>
    	<key>Application Version</key><string>9.0.2</string>
    	<key>Features</key><integer>5</integer>
    	<key>Show Content Ratings</key><true/>
    	<key>Music Folder</key><string>file://localhost/Users/Comeoff/Music/iTunes/iTunes%20Music/</string>
    	<key>Library Persistent ID</key><string>74A9CE791AEBAC3B</string>
    	<key>Tracks</key>
    	<dict>
    		<key>4418</key>
    		<dict>
    			<key>Track ID</key><integer>4418</integer>
    			<key>Name</key><string>Axwell - I Found You (Danyo Wallem 2010 Remix) [Stereo-Audio.ru]</string>
    			<key>Genre</key><string>House</string>
    			<key>Kind</key><string>Аудиофайл MPEG</string>
    			<key>Size</key><integer>18169297</integer>
    			<key>Total Time</key><integer>454200</integer>
    			<key>Year</key><integer>2009</integer>
    			<key>BPM</key><integer>130</integer>
    			<key>Date Modified</key><date>2010-01-05T18:55:25Z</date>
    			<key>Date Added</key><date>2010-01-05T19:16:19Z</date>
    			<key>Bit Rate</key><integer>320</integer>
    			<key>Sample Rate</key><integer>48000</integer>
    			<key>Album Rating</key><integer>80</integer>
    			<key>Album Rating Computed</key><true/>
    			<key>Persistent ID</key><string>FDD9502CF0FF9C7F</string>
    			<key>Track Type</key><string>File</string>
    			<key>Location</key><string>file://localhost/Users/Comeoff/Music/iTunes/iTunes%20Music/Unknown%20Artist/Unknown%20Album/Axwell%20-%20I%20Found%20You%20(Danyo%20Wallem%202010%20Remix)%20%5BStereo-Audio.ru%5D.mp3</string>
    			<key>File Folder Count</key><integer>4</integer>
    			<key>Library Folder Count</key><integer>1</integer>
    		</dict>
    		<key>4420</key>
    		<dict>
    			<key>Track ID</key><integer>4420</integer>
    			<key>Name</key><string>Daft Punk - Harder Better Faster Stronger (Rolvario Edit) [Stereo-Audio.ru]</string>
    			<key>Kind</key><string>Аудиофайл MPEG</string>
    			<key>Size</key><integer>18520861</integer>
    			<key>Total Time</key><integer>462915</integer>
    			<key>Date Modified</key><date>2010-01-05T18:49:13Z</date>
    			<key>Date Added</key><date>2010-01-05T19:16:19Z</date>
    			<key>Bit Rate</key><integer>320</integer>
    			<key>Sample Rate</key><integer>44100</integer>
    			<key>Album Rating</key><integer>80</integer>
    			<key>Album Rating Computed</key><true/>
    			<key>Persistent ID</key><string>2A00CE3915BBFD0A</string>
    			<key>Track Type</key><string>File</string>
    			<key>Location</key><string>file://localhost/Users/Comeoff/Music/iTunes/iTunes%20Music/Unknown%20Artist/Unknown%20Album/Daft%20Punk%20-%20Harder%20Better%20Faster%20Stronger%20(Rolvario%20Edit)%20%5BStereo-Audio.ru%5D.mp3</string>
    			<key>File Folder Count</key><integer>4</integer>
    			<key>Library Folder Count</key><integer>1</integer>
    		</dict>
    		<key>4422</key>
    		<dict>
    			<key>Track ID</key><integer>4422</integer>
    			<key>Name</key><string>Robert Morr & Franz Xaver - Funking In The Studio (Original Mix)</string>
    			<key>Genre</key><string>House</string>
    			<key>Kind</key><string>Аудиофайл MPEG</string>
    			<key>Size</key><integer>17243771</integer>
    			<key>Total Time</key><integer>431072</integer>
    			<key>Year</key><integer>2009</integer>
    			<key>Date Modified</key><date>2010-01-05T18:55:07Z</date>
    			<key>Date Added</key><date>2010-01-05T19:16:19Z</date>
    			<key>Bit Rate</key><integer>320</integer>
    			<key>Sample Rate</key><integer>44100</integer>
    			<key>Album Rating</key><integer>80</integer>
    			<key>Album Rating Computed</key><true/>
    			<key>Persistent ID</key><string>02E5B19B73712338</string>
    			<key>Track Type</key><string>File</string>
    			<key>Location</key><string>file://localhost/Users/Comeoff/Music/iTunes/iTunes%20Music/Unknown%20Artist/Unknown%20Album/Robert%20Morr%20&%20Franz%20Xaver%20-%20Funking%20In%20The%20Studio%20(Original%20Mix).mp3</string>
    			<key>File Folder Count</key><integer>4</integer>
    			<key>Library Folder Count</key><integer>1</integer>
    		</dict>
    		<key>4424</key>
    		<dict>
    			<key>Track ID</key><integer>4424</integer>
    			<key>Name</key><string>Danny-S & TAITO - Rainbow (Dirty Rush Remix) [Stereo-Audio.ru]</string>
    			<key>Genre</key><string>Blues</string>
    			<key>Kind</key><string>Аудиофайл MPEG</string>
    			<key>Size</key><integer>18607650</integer>
    			<key>Total Time</key><integer>465162</integer>
    			<key>Date Modified</key><date>2010-01-05T18:48:26Z</date>
    			<key>Date Added</key><date>2010-01-05T19:16:20Z</date>
    			<key>Bit Rate</key><integer>320</integer>
    			<key>Sample Rate</key><integer>44100</integer>
    			<key>Album Rating</key><integer>80</integer>
    			<key>Album Rating Computed</key><true/>
    			<key>Persistent ID</key><string>466082161014FB2E</string>
    			<key>Track Type</key><string>File</string>
    			<key>Location</key><string>file://localhost/Users/Comeoff/Music/iTunes/iTunes%20Music/Unknown%20Artist/Unknown%20Album/Danny-S%20&%20TAITO%20-%20Rainbow%20(Dirty%20Rush%20Remix)%20%5BStereo-Audio.ru%5D.mp3</string>
    			<key>File Folder Count</key><integer>4</integer>
    			<key>Library Folder Count</key><integer>1</integer>
    		</dict>
    		<key>4426</key>
    		<dict>
    			<key>Track ID</key><integer>4426</integer>
    			<key>Name</key><string>Aaron Smith ft. Lauren Ritchie - Youll never find (Aaron Smiths original mix) [Stereo-Audio.ru]</string>
    			<key>Genre</key><string>Other</string>
    			<key>Kind</key><string>Аудиофайл MPEG</string>
    			<key>Size</key><integer>20519247</integer>
    			<key>Total Time</key><integer>512940</integer>
    			<key>Year</key><integer>2009</integer>
    			<key>Date Modified</key><date>2010-01-05T19:11:15Z</date>
    			<key>Date Added</key><date>2010-01-05T19:16:20Z</date>
    			<key>Bit Rate</key><integer>320</integer>
    			<key>Sample Rate</key><integer>44100</integer>
    			<key>Album Rating</key><integer>80</integer>
    			<key>Album Rating Computed</key><true/>
    			<key>Persistent ID</key><string>323AA6A466DD544A</string>
    			<key>Track Type</key><string>File</string>
    			<key>Location</key><string>file://localhost/Users/Comeoff/Music/iTunes/iTunes%20Music/Unknown%20Artist/Unknown%20Album/Aaron%20Smith%20ft.%20Lauren%20Ritchie%20-%20Youll%20never%20find%20(Aaron%20Smiths%20original%20mix)%20%5BStereo-Audio.ru%5D.mp3</string>
    			<key>File Folder Count</key><integer>4</integer>
    			<key>Library Folder Count</key><integer>1</integer>
    		</dict>
    		<key>4428</key>
    		<dict>
    			<key>Track ID</key><integer>4428</integer>
    			<key>Name</key><string>Divorce (Original Mix)</string>
    			<key>Artist</key><string>Faarsheed</string>
    			<key>Genre</key><string>House</string>
    			<key>Kind</key><string>Аудиофайл MPEG</string>
    			<key>Size</key><integer>18745717</integer>
    			<key>Total Time</key><integer>468610</integer>
    			<key>Year</key><integer>2009</integer>
    			<key>Date Modified</key><date>2010-01-05T18:51:06Z</date>
    			<key>Date Added</key><date>2010-01-05T19:16:20Z</date>
    			<key>Bit Rate</key><integer>320</integer>
    			<key>Sample Rate</key><integer>44100</integer>
    			<key>Persistent ID</key><string>603423BA2AF54F40</string>
    			<key>Track Type</key><string>File</string>
    			<key>Location</key><string>file://localhost/Users/Comeoff/Music/iTunes/iTunes%20Music/Faarsheed/Unknown%20Album/Divorce%20(Original%20Mix).mp3</string>
    			<key>File Folder Count</key><integer>4</integer>
    			<key>Library Folder Count</key><integer>1</integer>
    		</dict>
    	</dict>
    	<key>Playlists</key>
    	<array>
    		<dict>
    			<key>Name</key><string>stereo 05</string>
    			<key>Playlist ID</key><integer>8461</integer>
    			<key>Playlist Persistent ID</key><string>460EE7F4C5AA8A5A</string>
    			<key>All Items</key><true/>
    			<key>Playlist Items</key>
    			<array>
    				<dict>
    					<key>Track ID</key><integer>4418</integer>
    				</dict>
    				<dict>
    					<key>Track ID</key><integer>4420</integer>
    				</dict>
    				<dict>
    					<key>Track ID</key><integer>4422</integer>
    				</dict>
    				<dict>
    					<key>Track ID</key><integer>4424</integer>
    				</dict>
    				<dict>
    					<key>Track ID</key><integer>4426</integer>
    				</dict>
    				<dict>
    					<key>Track ID</key><integer>4428</integer>
    				</dict>
    			</array>
    		</dict>
    	</array>
    </dict>
    </plist>
    
    у кого есть время и кому не сложно написать скрипт, буду благодарен тем людям :)
     
  2. vvy

    vvy New Member

    Joined:
    29 Mar 2009
    Messages:
    33
    Likes Received:
    3
    Reputations:
    4
    PHP:
    $my_xml.='........';// переменная с xml-данными
    preg_match_all('~<key>Name</key><string>([^\r\n]*)</string>~',$my_xml,$mos);
    for (
    $i=0;$i<count($mos);$i++)
        echo 
    $mos[1][$i].'<br>';
    ЗЫ А вобще не линтяйничай
     
    1 person likes this.
  3. b3

    b3 Moderator

    Joined:
    5 Dec 2004
    Messages:
    2,027
    Likes Received:
    913
    Reputations:
    199
    http://ua2.php.net/xml_parse_into_struct
     
    _________________________
    1 person likes this.
Loading...