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

2005-02-03 Thread Richard Lynch
Jerry Miller wrote:
 There's a FAQ section entitled PHP and Other Languages,
 C isn't even listed among them!

Neither is COBOL. :-)

But you could Google for PHP and C and probably come up with something
worth reading.

But do feel free to write up a new section for the manual.

You can skip doing the COBOL one, however. :-)

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2005-02-03 Thread Richard Lynch
Jerry Miller wrote:
 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 BRcont: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:

 000 177   E   L   F

 All four bytes are non-zero!

http://us4.php.net/language.types.type-juggling

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2005-02-02 Thread Jerry Miller
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 BRcont: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:

000 177   E   L   F

All four bytes are non-zero!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2005-02-02 Thread Jerry Miller
There's a FAQ section entitled PHP and Other Languages,
C isn't even listed among them!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2005-02-02 Thread Jason Wong
On Thursday 03 February 2005 07:00, Jerry Miller wrote:
 There's a FAQ section entitled PHP and Other Languages,
 C isn't even listed among them!

Neither is Prolog, Pascal, ADA, ...,

The point you seem to be missing is that PHP is geared mainly towards creating 
web pages, that's why ASP, Perl, and Cold Fusion are listed.

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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2005-02-02 Thread DvDmanDT
It's a pretty big difference, so there's logic for that.. You can't really
compare them.. Not in my opinion anyway..

-- 
// DvDmanDT
MSN: dvdmandt¤hotmail.com
Mail: dvdmandt¤telia.com
Jerry Miller [EMAIL PROTECTED] skrev i meddelandet
news:[EMAIL PROTECTED]
 There's a FAQ section entitled PHP and Other Languages,
 C isn't even listed among them!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2005-02-02 Thread Jason Wong
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:

 000 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2005-02-02 Thread DvDmanDT
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 [EMAIL PROTECTED] skrev i meddelandet
news:[EMAIL PROTECTED]
 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 BRcont: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:

 000 177   E   L   F

 All four bytes are non-zero!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2005-02-02 Thread DvDmanDT
PHP files can be named whatever you want.. Just know that they are parsed on
the serverside, not the client side.. Therefore, text/php would be pretty
stupid to do.. And I don't know what you mean be that script thing, you
probably don't even understand what PHP is when you make that statement..

There's no problem with PHP.. I've done lots of binary work with it without
problems.. And I do have some experience with C as well.. And with C++.. You
probably just don't understand the idea of PHP.. The idea is definitly not
to be another C or C++.. It's to be an easy, but powerful, webscripting
language.. And it is..

-- 
// DvDmanDT
MSN: dvdmandt¤hotmail.com
Mail: dvdmandt¤telia.com
Jerry Miller [EMAIL PROTECTED] skrev i meddelandet
news:[EMAIL PROTECTED]
 Is there an example of the UNIX od utility written
 in PHP?  Is such a useful task even possible??
 From what I've seen of strings, they're completely
 opaque, so what good does it do to be able to read
 binary-safe strings from a file???  Even the deprecated
 (why) $str{$inx} notation apparently results in
 another string, because trying to printf it with the
 %02x format always comes out with 00.  (Maybe
 that's why -- it's useless!)  As an experienced C
 programmer, I'm finding PHP to be as counter-intuitive
 for low-level work as Perl is.  I need to convert binary
 dumps of data structures into database table rows, and
 MySQL on my server doesn't support queries from C.

 I thought about writing a CGI script (in C) that
 would generate the hard-coded PHP output for
 each instance, but a URL that ends in .cgi is
 never intercepted by the PHP interpreter.  Worse
 yet, the SCRIPT LANGUAGE= SRC=
 that works perfectly well with JavaScript is
 likewise ignored if the language is PHP!  Finally,
 I'm not aware of a Content-type such as text/php.
 What exactly was the purpose of designing yet
 another inflexible language?!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php