Convert TXT to XML 04.06.15 19:15
Para converter precisa somente colocar a furnidata.txt no mesmo diretório do script e executar no navegador
Download (Comente para ver)
- Código:
<?php
class Furnidata_Convert {
public $filename_txt = "furnidata.txt";
public $data;
public function __construct() {
set_time_limit(0);
error_reporting(0);
ob_start();
$this->getContent();
$this->ConvertFile();
$this->WriteFile();
}
private function getContent() {
$data = file_get_contents($this->filename_txt);
$data = utf8_encode($data);
return $data;
}
private function WriteFile() {
$tampon = ob_get_contents();
ob_end_clean();
$fichier = fopen('furnidata.xml', 'w+');
$resultat = fwrite($fichier, $tampon);
fclose($fichier);
}
private function ConvertFile() {
echo '<?xml version="1.0"?>
<furnidata>
<roomitemtypes>';
$data = str_replace("&", "et", $data);
$data = str_replace("<", "", $data);
foreach(explode('[',$data) as $premier) {
$var = explode('",',$premier);
$var = str_replace('"','', $var);
$var = str_replace('],','', $var);
if($var[0] == 's') {
echo '<furnitype id="'.$var[1].'" classname="'.$var[2].'">
<revision>'.$var[3].'</revision>
<defaultdir>'.$var[4].'</defaultdir>
<xdim>'.$var[5].'</xdim>
<vdim>'.$var[6].'</vdim>
<partcolors>';
$colors = explode(',', $var[7]);
foreach($colors as $color) {
echo '<color>'.$color.'</color>';
}
echo '</partcolors>
<name>'.$var[8].'</name>
<description>'.$var[9].'</description>
<adurl></adurl>
<offerid>0</offerid>
<buyout>0</buyout>
<rentofferid>-1</rentofferid>
<rentbuyout>0</rentbuyout>
<customparams>';
if(empty($var[13]) && !isset($var[13])) {
echo '1';
} else {
echo $var[13];
}
echo '</customparams>
<specialtype>';
if(empty($var[14]) && !isset($var[14])) {
echo '1';
} else {
echo $var[14];
}
echo '</specialtype>
<canstandon>0</canstandon>
<cansiton>0</cansiton>
<canlayon>0</canlayon>
</furnitype>';
}
}
echo '</roomitemtypes>
<wallitemtypes>';
foreach(explode('[',$data) as $premier) {
$var = explode('",',$premier);
$var = str_replace('"','', $var);
if($var[0] == 'i') {
echo '<furnitype id="'. $var[1].'" classname="'.$var[2].'"
<revision>'.$var[3].'</revision>
<name>'.$var[8].'</name>
<description>'.$var[9].'</description>
<adurl></adurl>
<offerid>0</offerid>
<buyout>0</buyout>
<rentofferid>-1</rentofferid>
<rentbuyout>0</rentbuyout>
<specialtype>1</specialtype>
</furnitype>
';
}
}
echo '</wallitemtypes>
</furnidata>';
}
}
new Furnidata_Convert;