Parse xml and send datas to MySQL database
Posted: Tue May 18, 2010 3:06 pm
Hi for everybody who reading this post, i`m new in php and need some help. I want to write a small script to parse xml file (from file) and send datas to table. Here is the prototype of code, but i need more help to finishing.
Here is the .html (xml) document online: http://www.ika.timberpro.net/test/fajlok/001b.html
Here is the code:
But is not complete and very large and no connection to the database.
I want to use a separate file for storing connect details.
Best Regards,
Gabor
Here is the .html (xml) document online: http://www.ika.timberpro.net/test/fajlok/001b.html
Here is the code:
Code: Select all
<?php
/**
* @author Gabika
* @copyright 2010
*/
if ($handle = opendir('fajlok/')) {
$i=0;
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$file_handle = fopen("fajlok/".$file, "r");
$file_contents = fread($file_handle, filesize('fajlok/'.$file));
$array[$i]=explode("<li class=\"name\">"."<span class=\"textLabel\">"."Név: </span>", $file_contents);
for($j=0; $j<count($array[$i]); $j++) {
$temp=explode("</li>", $array[$i][$j]);
$array[$i][$j]=$temp[0];
}
fclose($file_handle);
$array[$i][0]="";
$i++;
}
}
closedir($handle);
}
for($k=0; $k<count($array); $k++){
for($l=1; $l<count($array[$k]); $l++){
echo "$l ".$array[$k][$l]."<br/>";
}
}
if ($handle = opendir('fajlok/')) {
$i=0;
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$file_handle = fopen("fajlok/".$file, "r");
$file_contents = fread($file_handle, filesize('fajlok/'.$file));
$array[$i]=explode("<li class=\"citylevel\">"."<span class=\"textLabel\">"."Város mérete: </span>", $file_contents);
for($j=0; $j<count($array[$i]); $j++) {
$temp=explode("</li>", $array[$i][$j]);
$array[$i][$j]=$temp[0];
}
fclose($file_handle);
$array[$i][0]="";
$i++;
}
}
closedir($handle);
}
for($k=0; $k<count($array); $k++){
for($l=1; $l<count($array[$k]); $l++){
echo "$l ".$array[$k][$l]."<br/>";
}
}
if ($handle = opendir('fajlok/')) {
$i=0;
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$file_handle = fopen("fajlok/".$file, "r");
$file_contents = fread($file_handle, filesize('fajlok/'.$file));
$array[$i]=explode("<li class=\"owner\">"."<span class=\"textLabel\">"."Játékos: </span>", $file_contents);
for($j=0; $j<count($array[$i]); $j++) {
$temp=explode("</li>", $array[$i][$j]);
$array[$i][$j]=$temp[0];
}
fclose($file_handle);
$array[$i][0]="";
$i++;
}
}
closedir($handle);
}
for($k=0; $k<count($array); $k++){
for($l=1; $l<count($array[$k]); $l++){
echo "$l ".$array[$k][$l]."<br/>";
}
}
if ($handle = opendir('fajlok/')) {
$i=0;
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$file_handle = fopen("fajlok/".$file, "r");
$file_contents = fread($file_handle, filesize('fajlok/'.$file));
$array[$i]=explode("<li class=\"name\">"."<span class=\"textLabel\">"."Pontok: </span>", $file_contents);
for($j=0; $j<count($array[$i]); $j++) {
$temp=explode("</li>", $array[$i][$j]);
$array[$i][$j]=$temp[0];
}
fclose($file_handle);
$array[$i][0]="";
$i++;
}
}
closedir($handle);
}
for($k=0; $k<count($array); $k++){
for($l=1; $l<count($array[$k]); $l++){
echo "$l ".$array[$k][$l]."<br/>";
}
}
if ($handle = opendir('fajlok/')) {
$i=0;
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$file_handle = fopen("fajlok/".$file, "r");
$file_contents = fread($file_handle, filesize('fajlok/'.$file));
$array[$i]=explode("<li class=\"ally\">"."<span class=\"textLabel\">"."Szövetség: </span>", $file_contents);
for($j=0; $j<count($array[$i]); $j++) {
$temp=explode("</li>", $array[$i][$j]);
$array[$i][$j]=$temp[0];
}
fclose($file_handle);
$array[$i][0]="";
$i++;
}
}
closedir($handle);
}
for($k=0; $k<count($array); $k++){
for($l=1; $l<count($array[$k]); $l++){
echo "$l ".$array[$k][$l]."<br/>";
}
}
?>I want to use a separate file for storing connect details.
Best Regards,
Gabor