World of Warcraft
Starcraft
Warcraft 3
Starcraft 2

PHP Snippets

From Source Peek Wiki

Jump to: navigation, search

Reading a string block into a variable

$str_block = file_get_contents($file_path,FALSE,NULL,(($Records * $RecordSize) + 20)); // requires PHP 5.1.0

To use get your var's from the head of the file.

$_hdr_data[] = $file_name; // just a little extra info; passed to $Header
$file_format = fread($fh, 4); // be sure to fopen the file! 
if($file_format == "WDBC") // is this a DBC file?
{
	for($i = 0; $i < 4; $i++)
	{
		$bin = fread($fh, 4);
		$hex = bin2hex($bin);
		$hex = substr($hex, 6, 2).substr($hex, 4, 2).substr($hex, 2, 2).substr($hex, 0, 2);
		$_hdr_data[] = hexdec($hex);
	}
	list($Header,$Records,$Fields,$RecordSize,$BlockSize) = $_hdr_data;
}
This page was last modified on 22 January 2007, at 23:48. This page has been accessed 995 times.