[PHP] Problem solved!

2005-02-03 Thread Jerry Miller
I didn't want to give up entirely on the
flexibility of writing my scripts in C, so
I thought some more about how to get
a CGI script to use PHP without having
to spend a lot of time on PHP logic.

My first attempt was to see whether I
could substitute the extension .php
for the usual .cgi extension.  I could,
but it made no difference, i.e., PHP
didn't intercept the output.

I did some searching in /usr/local/lib/php
to no avail, but then I brought up the
phpinfo page and studied it.  Under the
Environment heading, I found the
variable SCRIPT_FILENAME and
passed it a test PHP filename as a
command-line argument.  Voila!  I
got a HTTP header and the expected
PHP-processed output!

Now all I have to do is use popen from
the C program that will become my CGI
script, and I'll be able to let C handle the
GET and/or POST query strings, create
the MySQL queries, and pass a more
manageable amount of PHP code to
access the tables.  Using HTTPS should
also be more straightforward that way.

I knew there had to be a better way!

-- 
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] How to make binary strings useful?

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



[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] How to make binary strings useful?

2005-02-02 Thread Jerry Miller
That should help.  Thanks.

Chris [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 I've written complete file parsers in PHP, and the only snag I've run
 into is dealing Signed integers (and larger).


 Jerry Miller wrote:

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

 the pack() and unpack() functions  are used to remove data from and
 place data into binary strings.

 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!)
 
 $str{$inx} does return a single character string, in order to get the
 numerical value, try using ord()

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

 Chris

 http://www.php.net/pack
 http://www.php.net/unpack
 http://www.php.net/ord
 http://www.php.net/chr

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