Kodları lütfen aşağıdaki butonları kullanarak renklendirin. Örnek: <php> echo "Selam Dünya"; </php>
Yardım
karakter kaldı

php ile xml dosyası oluşturmak

selam,internette gezinirken xml dosyası oluşturmayla ilgili güzel bir örnek bulmuştum ancak format sonrası kaybettim. şimdide bulamıyorum. sorum şu:
"müzik" isminde bir dosyam var içindede "mp3" ler var. php kodunu localhost yada başka bir hostda çalıştırdığımda bana xmi dosyası oluştursun. bu ekrana yazdırma ile de olabilir,yeni bir xml dosyası oluşturması da olabilir.saygılar.
+0
-0
Cevaba KatılıyorumKatılmıyorum
Cevap Yaz Yorum Yaz Arşivime Ekle Takip Et

Doğru Cevap

  • Hasan adlı üyenin fotoğrafı
    11 yıl önce yazılmış
    63 cevap - 0 soru
    $music_dir   = './music/';     // Put the pathname of your music directory here.
    $output_file = './music.xml';  // Put the pathname of where you want to put the xml file here.
    
    $mp3_files = glob($music_dir . '*.mp3');
    foreach ($mp3_files as $each) {
        $info[] = get_tags($each);
    }
    $xml = make_xml_doc($info);
    file_put_contents($output_file, $xml);
    
    // These three lines for devlopment. Remove for production.
    echo '<pre>';
    echo htmlspecialchars(file_get_contents($output_file));
    echo '</pre>';
    
    function make_xml_doc($data)
    {
        $xmlw = new XMLWriter;
        $xmlw->openMemory();
        $xmlw->setIndentString('  ');
        $xmlw->setIndent(true);
        $xmlw->startDocument();
        $xmlw->startElement('playList');
        $xmlw->writeAttribute('version', '1');
        $xmlw->writeAttribute('xmlns', 'http://xspf.org/ns/0/');
        $xmlw->startElement('trackList');
        foreach ($data as $track) {
            $xmlw->startElement('track');
            $xmlw->writeElement('location', $track['location']);
            $xmlw->writeElement('title', $track['title']);
            $xmlw->writeElement('creator', $track['creator']);
            $xmlw->endElement();
        }
        $xmlw->endElement();
        $xmlw->endElement();
        $xmlw->endDocument();
        $doc = $xmlw->flush();
        return $doc;
    }
    
    function get_tags($file, $tags = array('title', 'artist'))
    {
        $cmd_str = 'Tag "' . $file . '" 2>&1';
        $ret = exec($cmd_str, $output);
        $arr = array();
        $arr['location'] = $file;
        foreach ($tags as $tag) {
            $found = false;
            foreach ($output as $line) {
                if (stripos($line, $tag) === 0) {
                    $pos = strpos($line, ':');
                    if ($tag == 'artist') {
                        $tag = 'creator';
                    }
                    $arr[$tag] = trim(strip_tags(substr($line, $pos + 1)));
                    $found = true;
                    break;
                }
            }
            if (!$found) {
                $arr[$tag] = '-not present-';
            }
        }
        return $arr;
    } 
    
    




    Çıktısı :

    
    <?xml version="1.0"?>
    <playList version="1" xmlns="http://xspf.org/ns/0/">
      <trackList>
        <track>
          <location>./music/Kalimba.mp3</location>
          <title>-not present-</title>
          <creator/>
        </track>
        <track>
          <location>./music/Maid with the Flaxen Hair.mp3</location>
          <title>-not present-</title>
          <creator/>
        </track>
        <track>
          <location>./music/Sleep Away.mp3</location>
          <title>-not present-</title>
          <creator/>
        </track>
      </trackList>
    </playList>
    
    
    • ahmet27 adlı üyenin fotoğrafı ahmet27
      teşekkürederim kardeşim sanıyorum aradığım bu. Ellerine sağlık.
      11 yıl önce yazılmış
    • ahmet27 adlı üyenin fotoğrafı ahmet27
      evet bu. çalışıyor. dosyamdaki mp3 lokasyon etiketleri arasına yazdırıyor ama title etiketi arasına müzik ismini nasıl yazdıracağım?sanıyorum html form hazırlamak gerek. öyle değilmi?
      11 yıl önce yazılmış
    • Hasan adlı üyenin fotoğrafı Hasan
      Biraz değiştirdim...

      $music_dir   = './music/';     // Put the pathname of your music directory here.
      $output_file = './music.xml';  // Put the pathname of where you want to put the xml file here.
      
      $mp3_files = glob($music_dir . '*.mp3');
      foreach ($mp3_files as $each) {
          $info[] = tagReader($each);
      }
      
      $xml = make_xml_doc($info);
      file_put_contents($output_file, $xml);
      
      // These three lines for devlopment. Remove for production.
      echo '<pre>';
      echo htmlspecialchars(file_get_contents($output_file));
      echo '</pre>';
      
      function make_xml_doc($data)
      {	
          $xmlw = new XMLWriter;
          $xmlw->openMemory();
          $xmlw->setIndentString('  ');
          $xmlw->setIndent(true);
          $xmlw->startDocument();
          $xmlw->startElement('playList');
          $xmlw->writeAttribute('version', '1');
          $xmlw->writeAttribute('xmlns', 'http://xspf.org/ns/0/');
          $xmlw->startElement('trackList');
          foreach ($data as $track) {
              $xmlw->startElement('track');
              $xmlw->writeElement('location', $track['FileName']);
              $xmlw->writeElement('title', $track['Title']);
              $xmlw->writeElement('creator', $track['Author']);
              $xmlw->endElement();
          }
          $xmlw->endElement();
          $xmlw->endElement();
          $xmlw->endDocument();
          $doc = $xmlw->flush();
          return $doc;
      }
      
      function tagReader($file){
          $id3v23 = array("TIT2","TALB","TPE1","TRCK","TDRC","TLEN","USLT");
          $id3v22 = array("TT2","TAL","TP1","TRK","TYE","TLE","ULT");
          $fsize = filesize($file);
          $fd = fopen($file,"r");
          $tag = fread($fd,$fsize);
          $tmp = "";
          fclose($fd);
          if (substr($tag,0,3) == "ID3") {
              $result['FileName'] = $file;
              $result['TAG'] = substr($tag,0,3);
              $result['Version'] = hexdec(bin2hex(substr($tag,3,1))).".".hexdec(bin2hex(substr($tag,4,1)));
          }
          if($result['Version'] == "4.0" || $result['Version'] == "3.0"){
              for ($i=0;$i<count($id3v23);$i++){
                  if (strpos($tag,$id3v23[$i].chr(0))!= FALSE){
                      $pos = strpos($tag, $id3v23[$i].chr(0));
                      $len = hexdec(bin2hex(substr($tag,($pos+5),3)));
                      $data = substr($tag, $pos, 9+$len);
                      for ($a=0;$a<strlen($data);$a++){
                          $char = substr($data,$a,1);
                          if($char >= " " && $char <= "~") $tmp.=$char;
                      }
                      if(substr($tmp,0,4) == "TIT2") $result['Title'] = substr($tmp,4);
                      if(substr($tmp,0,4) == "TALB") $result['Album'] = substr($tmp,4);
                      if(substr($tmp,0,4) == "TPE1") $result['Author'] = substr($tmp,4);
                      if(substr($tmp,0,4) == "TRCK") $result['Track'] = substr($tmp,4);
                      if(substr($tmp,0,4) == "TDRC") $result['Year'] = substr($tmp,4);
                      if(substr($tmp,0,4) == "TLEN") $result['Lenght'] = substr($tmp,4);
                      if(substr($tmp,0,4) == "USLT") $result['Lyric'] = substr($tmp,7);
                      $tmp = "";
                  }
              }
          }
          if($result['Version'] == "2.0"){
              for ($i=0;$i<count($id3v22);$i++){
                  if (strpos($tag,$id3v22[$i].chr(0))!= FALSE){
                      $pos = strpos($tag, $id3v22[$i].chr(0));
                      $len = hexdec(bin2hex(substr($tag,($pos+3),3)));
                      $data = substr($tag, $pos, 6+$len);
                      for ($a=0;$a<strlen($data);$a++){
                          $char = substr($data,$a,1);
                          if($char >= " " && $char <= "~") $tmp.=$char;
                      }
                      if(substr($tmp,0,3) == "TT2") $result['Title'] = substr($tmp,3);
                      if(substr($tmp,0,3) == "TAL") $result['Album'] = substr($tmp,3);
                      if(substr($tmp,0,3) == "TP1") $result['Author'] = substr($tmp,3);
                      if(substr($tmp,0,3) == "TRK") $result['Track'] = substr($tmp,3);
                      if(substr($tmp,0,3) == "TYE") $result['Year'] = substr($tmp,3);
                      if(substr($tmp,0,3) == "TLE") $result['Lenght'] = substr($tmp,3);
                      if(substr($tmp,0,3) == "ULT") $result['Lyric'] = substr($tmp,6);
                      $tmp = "";
                  }
              }
          }
          return $result;
      }
      




      Çıktısı :

      <?xml version="1.0"?>
      <playList version="1" xmlns="http://xspf.org/ns/0/">
        <trackList>
          <track>
            <location>./music/Kalimba.mp3</location>
            <title>Kalimb</title>
            <creator>Mr. Scruf</creator>
          </track>
          <track>
            <location>./music/Maid with the Flaxen Hair.mp3</location>
            <title>Maid with the Flaxen Hai</title>
            <creator>2Richard Stoltzman/Slovak Radio Symphony Orchestr</creator>
          </track>
          <track>
            <location>./music/Sleep Away.mp3</location>
            <title>Sleep Awa</title>
            <creator>Bob Acr</creator>
          </track>
        </trackList>
      </playList>
      
      11 yıl önce yazılmış
    • ahmet27 adlı üyenin fotoğrafı ahmet27
      çok teşekkür ederim tam istediğim gibi olmuş,harikasın, sağol kardeş azmin ve bilgin hep daim olsun.
      11 yıl önce yazılmış
    • ahmet27 adlı üyenin fotoğrafı ahmet27
      merhaba, yukarıda "biraz değiştirdim" dediğiniz ve çıktısı altda olan kodların aynısını bir html form hazırlayıp aynı şekide xml dosyası oluşturamazmıyız. bu konuda yardım, ya da kaynak gösterirseniz sevinirim.
      11 yıl önce yazılmış
    • Hasan adlı üyenin fotoğrafı Hasan
      <?php
      
      $output_file = './music-form.xml';  // Put the pathname of where you want to put the xml file here.
      
      $data = ($_POST) ? $_POST : '';
      if($data !=''){
      	$xml = make_xml_doc($data);
      	file_put_contents($output_file, $xml);
      	
      	// These three lines for devlopment. Remove for production.
      	echo '<pre>';
      	echo htmlspecialchars(file_get_contents($output_file));
      	echo '</pre>';
      }
      
      function make_xml_doc($data)
      {	
          $xmlw = new XMLWriter;
          $xmlw->openMemory();
          $xmlw->setIndentString('  ');
          $xmlw->setIndent(true);
          $xmlw->startDocument();
          $xmlw->startElement('playList');
          $xmlw->writeAttribute('version', '1');
          $xmlw->writeAttribute('xmlns', 'http://xspf.org/ns/0/');
          $xmlw->startElement('trackList');
      	$xmlw->startElement('track');
      	
      	$xmlw->writeElement('location', $data['FileName']);
          $xmlw->writeElement('title', $data['Title']);
          $xmlw->writeElement('creator', $data['Author']);
          
      	$xmlw->endElement();
          $xmlw->endElement();
          $xmlw->endElement();
          $xmlw->endDocument();
          $doc = $xmlw->flush();
          return $doc;
      }
      
      ?>
      
      <form name="musicForm" action="" method="post">
      	Filename : <input type="text" name="FileName" />
      	<br />
      	Title : <input type="text" name="Title" />
      	<br />
      	Author : <input type="text" name="Author" />
      	
      	<br/><br/>
      	<input type="submit" />
      </form>
      
      11 yıl önce yazılmış
    • Hasan adlı üyenin fotoğrafı Hasan
      Geliştirmesini yaparsın.
      11 yıl önce yazılmış
    • ahmet27 adlı üyenin fotoğrafı ahmet27
      Tek kelimeyle harikasın çok teşekkürler kardeş. evet ben artık gerisini hallederim. sana başarılar dilerim.sağol.
      11 yıl önce yazılmış

Cevaplar

  • siyahbeyaz adlı üyenin fotoğrafı
    11 yıl önce yazılmış
    472 cevap - 20 soru
    :)) kendim icin yazdıgım sitemap.xml oluşturan kod.. kendine göre uyarlarsın..
    <?
    include("../db.php");
    header("content-type:text/html; charset=utf-8"); 
    $dosya_ismi = "../sitemap.xml";
    $dosyadi = "../sitemap.xml.gz"; //ftp kaydedilecek dosya adı
    $publ = mysql_query("select id,tarih from videolar order by id desc");
    $virikili = mysql_fetch_assoc($publ);
    $publicdate=$virikili["tarih"];
    mysql_free_result($publ);
      
    @unlink($dosya_ismi);
    @unlink($dosyadi);
    
    if(!@touch($dosya_ismi)) {
    echo "$dosya_ismi oluşturulamadı";
    } else {
    $metin ='<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="'.ayarlar('site_url').'/xsl/sitemap.xsl"?>
    <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> ';
    $metin =$metin.'
            <url>
            <loc>'.site('site_url').'/</loc>
            <lastmod>'.strftime("%Y-%m-%dT%H:%M:%S+00:00",strtotime($publicdate)).'</lastmod>
            <changefreq>daily</changefreq>
            <priority>1.0</priority>
        </url>';
    
        $ziyo=mysql_query("select google,tarih,id from videolar order by id desc");
        while($rs=mysql_fetch_object($ziyo)) {
    $metin =$metin.'
        <url>
            <loc>'.video_url()."/".$rs->google .'.html</loc>
            <lastmod>'.strftime("%Y-%m-%dT%H:%M:%S+00:00",strtotime($rs->tarih)).'</lastmod>
            <changefreq>monthly</changefreq>
            <priority>0.2</priority>
        </url>';
        }
        $yazkizimmelehat=mysql_query("select id,kgoogle from kategoriler where ne='kat' order by id desc");
        while($hakimamca=mysql_fetch_object($yazkizimmelehat)) {
    $metin =$metin.'
        <url>
            <loc>'.site('site_url').'/'.site('seo_kategori')."/".$hakimamca->kgoogle .'</loc>
            <lastmod>'.strftime("%Y-%m-%dT%H:%M:%S+00:00",strtotime($publicdate)).'</lastmod>
            <changefreq>monthly</changefreq>
            <priority>0.2</priority>
        </url>';        
        } mysql_free_result($yazkizimmelehat);
    $metin =$metin.'</urlset>
    ';
    
        if(file_put_contents($dosya_ismi, $metin,FILE_APPEND)) {
            $veri = file_get_contents($dosya_ismi);
            $ziplenenveri = gzencode($veri);
            $fh = fopen("$dosyadi", "w"); 
            fwrite($fh,$ziplenenveri);
            fclose($fh);
            echo '
            <div class="group">
            <h2>SiteMap oluşturuldu.</h2>
            <div style="padding:12px;">
            <strong>xml.gz URL: <a href="'.ayarlar('site_url').'/sitemap.xml.gz">'.ayarlar('site_url').'/sitemap.xml.gz</a></strong> <br />
            <strong>xml URL: <a href="'.ayarlar('site_url').'/sitemap.xml">'.ayarlar('site_url').'/sitemap.xml</a></strong>
            
            <br /><br />İçeriğiniz 5.000 üstündeyse google webmaster tools hesabına sadece <strong>sitemap.xml.gz</strong> yi ekleyin... <br />
            hem <strong>maptag.xml</strong> hemde <strong>sitemap.xml.gz</strong> ikisini aynı anda kullanmayınız..
            
           </div> </div>';
            
             
            
            } else {
            echo $dosya_ismi." oluşturulamadı...";
        }     
       
    
     
    }
    ?>
    
    
    • ahmet27 adlı üyenin fotoğrafı ahmet27
      teşekkür ederim bunu kullanacağım, soğol
      11 yıl önce yazılmış
  • 1
    erdemuzun adlı üyenin fotoğrafı
    11 yıl önce yazılmış
    10 cevap - 0 soru
    htacces ile bunu direk olarak yapabilirsin.
    İlla dosya olarak kaydetmek zorundaysan tabi ki bu şekilde de yapabilirsin.