Reply to Re: [PHP] RE: How to make binary strings useful?

Your name:

Reply:


Posted by Jason Wong on 10/04/33 11:07

On Thursday 03 February 2005 05:46, Jerry Miller wrote:
> Here's the code (with the domain name removed)
> that doesn't work, "despite" the poor documentation
> of the variable types:

> $filename = sprintf ("%s%s", $dir, $file);

Wouldn't

$filename = $dir . $file;

be easier?

> printf ("%02x %02x %02x %02x", $cont{0}, $cont{1}, $cont{2},
> $cont{3});

What is happening here is that (as stated in the manual) the format code '%x'
will treat the argument ($cont{1}) as an integer and display in hex format.
Because $cont{x} is a string, PHP's auto type conversion kicks in. So for
example $cont{1} is 'E', coverting to integer makes it 0 (zero), hence what
you are seeing.

> 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!

What you need is something like:

printf ("%02x %02x %02x %02x", ord($cont{0}), ord($cont{1}), ord($cont{2}),
ord($cont{3}));

Also check out unpack().

--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
New Year Resolution: Ignore top posted posts

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация