XML DOSYASI:
<?xml version="1.0" encoding="utf-8" ?>
<urun>
	<urun_aktif>1</urun_aktif>
	<urun_kod>724</urun_kod>
	<urun_ad>Tens Cihazı</urun_ad>
	<urun_ust_kategori_kod>0</urun_ust_kategori_kod>
	<urun_ust_kategori_ad/>
	<urun_kategori_kod>64</urun_kategori_kod>
	<urun_kategori_ad>TV ÜRÜNLERİ</urun_kategori_ad>
	<urun_marka_kod>23</urun_marka_kod>
	<urun_marka_ad>Tv Ürünleri</urun_marka_ad>
	<sonfiyat>35</sonfiyat>
	<piyasafiyat>0</piyasafiyat>
	<urun_aciklama>
		<p>ürün açıklama bölümü</p>
	</urun_aciklama>
	<urun_ozellikler></urun_ozellikler>
	<urun_resim1>http://siteadim.com/images/urunler/tense-724.jpg</urun_resim1>
	<urun_resim2>http://siteadim.com/images/urunler/tense-724.jpg</urun_resim2>
	<urun_resim3>http://siteadim.com/images/urunler/tens4-724.jpg</urun_resim3>
	<priceTekCekim/>
	<urun_fiyat_TL>29.661016949153</urun_fiyat_TL>
	<urun_fiyat_son_kullanici/>
	<urun_fiyat_bayi_ozel>29.66</urun_fiyat_bayi_ozel>
	<urun_doviz>TL</urun_doviz>
	<urun_kdv>0.18</urun_kdv>
	<urun_stok>-15</urun_stok>
	<urun_garanti>12</urun_garanti>
</urun>
PHP DOSYAMIZ:
<?php
/*
 * Mutlu ARICI - www.mutluarici.com - Web Based Software Developer
 * XML ile attribute ve element sorgulama - çekme
 * 22.07.2014
*/
header("Content-type: text/html;charset=UTF-8");
$dosya = file_get_contents("xml.test.xml");
$xml = simplexml_load_string($dosya) or die ("XML okunamiyor..");

echo "<h4>XML Icerik</h4>";
$toplamResim = 0;
foreach($xml as $attr=>$val) {
	echo "$attr - $val<br />";
	if (strpos($attr,"urun_resim") !== false) {
		$toplamResim++;
	}
}
echo "<hr />";
echo "<h4>Bulunan toplam resim: ".$toplamResim."</h4>";
for ($i=1;$i<=$toplamResim;$i++) {
	echo $i." -> ".ResimleriAl($xml,$i)."<br />";
}

//
function ResimleriAl($veri,$i) {
	foreach($veri as $attr=>$val) {
		if ($attr == "urun_resim".$i."") {
			return $val;
		}
	}
}
?>
Ankon adlı üyeden alıntı: mesajı görüntüle
Paylaşırsanız sevinirim hocam