You are not logged in.
#1 22 Mar 2007 11:43 pm
- sanman
- Member
- Registered: Mar 2007
- Posts: 12
BF2142 Stats table to PHP array
Code:
<?php $data=file_get_contents("data.txt"); $array=table2array($data); print_r($array); /** * table to array * @author * @param str $str * @return array */ function table2array($str){ $data=$str; $data=explode("\n",$data); $table_data=array(); $table_hedaer=array(); $table_index=array(); $result=array(); $s=0; foreach ($data AS $line) { $prefix=$line{0}; if($prefix=="O"){continue;} if($prefix=="$"){continue;} if($prefix=="H"){ $line=explode("\t",$line); $line_len=count($line); $table_hedaer[$s]=$line; $table_index[]=array($line_len,$s); $s++; } if($prefix=="D"){ $line=explode("\t",$line); $line_len=count($line); foreach ($table_index AS $index) { if ($index[0]==$line_len) { $out=array(); foreach ($table_hedaer[$index[1]] AS $keys) { $out[$keys] = array_shift($line); } $result[$index[1]][]=$out; } } } } return $result; }
http://www.kk.la/code/tabletoarray.php
http://www.kk.la/code/tabletoarray.phps
http://www.kk.la/code/data.dat
Last edited by sanman (22 Mar 2007 11:46 pm)
Offline
© 2003 - 2024 NullFX