PDA

View Full Version : Starcraft TBL reader in PHP


UED77
12-18-2005, 6:28 PM
I was experimenting with PHP, and I decided to create a short program that would read TBL files. For now, it's read-only, but I'm intent on creating a read-write one with the help of some Javascript.

Stable version (http://uedworld.webhop.net/test/php/tblread.php)
Development version (http://uedworld.webhop.net/test/php/tblreaddev.php)

Source:

<?php
// Open file
$file=fopen('tips.tbl', 'rb');

// Read first two bytes in LE to find num of entries
$len=ord(fread($file, 1))+ord(fread($file, 1))*256;
echo "<p>Number of entries: ".$len."</p>";

// Read offset table
for($i=0;$i<$len;$i++){
$table[$i]=ord(fread($file, 1))+ord(fread($file, 1))*256;
}

// Write out offset table
for($i=0;$i<$len;$i++){
echo $table[$i]."<br>";
}

//Failsafe Seek
fseek($file, $table[0]);

echo "<br>";

//Read out entries
for($i=0; $len-1>$i; $i++){
$entry = fread($file, $table[$i+1]-$table[$i]);
echo $entry."<br>";
}

fclose($file);
?>


UED77