Re: How to make binary strings useful?

From: Date: Wed, 02 Feb 2005 23:59:32 +0000
Subject: Re: How to make binary strings useful?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-207952@lists.php.net to get a copy of this message
You should use ord() on each of the $cont{} ones.. printf ("%02x %02x %02x %02x", ord($cont{0}), ord($cont{1}), ord($cont{2}), ord($cont{3})); That'll probably work much better.. .. PHP != C++, or C for that matter.. C was designed to be as close as possible to ASM, but high-level.. PHP is designed to be an easy to use web application language.. One char in PHP is a string with the length of 1, not a small integer.. Meaning that 'a' != 67 in php.. In C they would be equal.. Strings will be converted to integers by php, but you won't get the ascii code, you'll get something like the results of atoi() or something like that.. -- // DvDmanDT MSN: dvdmandt¤hotmail.com Mail: dvdmandt¤telia.com "Jerry Miller" <gamphd@optonline.net> skrev i meddelandet news:20050202214819.55348.qmail@lists.php.net... > Here's the code (with the domain name removed) > that doesn't work, "despite" the poor documentation > of the variable types: > > <? > $dir = "/home/<domain_name>/www/binary/"; > $dh = opendir ($dir); > do > { > $file = readdir ($dh); > } > while (!strncmp ($file, ".", 1)); > $filename = sprintf ("%s%s", $dir, $file); > $fh = fopen ($filename, "r"); > $cont = fread ($fh, 4); > echo "file:<BR>"; > echo $filename; > echo "<BR>cont:<BR>"; > printf ("%02x %02x %02x %02x", $cont{0}, $cont{1}, $cont{2}, > $cont{3}); > fclose ($fh); > closedir ($dh); > ?> > > Here's the output of "od -c glance_date" up to the fourth byte: > > 0000000 177 E L F > > All four bytes are non-zero!

« previous php.general (#207952) next »