http://www.koeri.boun.edu.tr/sismo/z.../son24saat.xml dosyası aşağıdaki şekilde:
<eqlist>
<earhquake Depth="8.7" mag="3.0" lng="26.1328" lat="40.3905" lokasyon="SAROS KORFEZI (EGE DENIZI) " name="2014.05.28 10:10:35"/>
<earhquake Depth="8.9" mag="1.6" lng="26.1293" lat="40.4288" lokasyon="SAROS KORFEZI (EGE DENIZI) " name="2014.05.28 10:14:07"/>
<earhquake Depth="9.6" mag="2.1" lng="26.1415" lat="40.3938" lokasyon="SAROS KORFEZI (EGE DENIZI) " name="2014.05.28 10:17:09"/>
</eqlist>
Bu verileri php ile veritabanına nasıl ekleyebilirim?
Xml den veritabanına kayıt
4
●608
- 29-05-2014, 11:09:04
<?php mysql_select_db('tablo_adi', mysql_connect('localhost', 'root', '123456')); function get_data($url){ $user_agent = $_SERVER['HTTP_USER_AGENT']; $ref = "http://www.koeri.boun.edu.tr"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); curl_setopt($ch, CURLOPT_REFERER, $ref); $fe = curl_exec($ch); curl_close($ch); return $fe; } function bosluk_sil($fe){ return str_replace(array("\n", "\r", "\t", " "), '', $fe); } $xml = bosluk_sil(get_data("http://www.koeri.boun.edu.tr/sismo/zeqmap/xmlt/son24saat.xml")); $desen = '@<earhquakename="(.*?)"lokasyon="(.*?)"lat="(.*?)"lng="(.*?)"mag="(.*?)"Depth="(.*?)"/>@'; preg_match_all($desen, $xml, $fe); $name = $fe[1]; $lokasyon = $fe[2]; $lat = $fe[3]; $lng = $fe[4]; $mag = $fe[5]; $depth = $fe[6]; $say = count($name); for($i=0; $i<$say-1; $i++){ $ekle = mysql_query("insert into tablo_adi (name, lokasyon, lat, lng, mag, depth) values ('$name[$i]', '$lokasyon[$i]', '$lat[$i]', '$lng[$i]', '$mag[$i]', '$depth[$i]')"); if($ekle){ echo "<font color='green'>Eklendi</font><br/>"; }else{ echo "<font color='red'>".mysql_error."</font><br/>"; } } ?>localde sorunsuz çalıştı.
http://i.imgur.com/IthpS6o.jpg