Re: perl-esque data parsing for hex post variables

From: Date: Thu, 30 Aug 2001 10:21:29 +0000
Subject: Re: perl-esque data parsing for hex post variables
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-65239@lists.php.net to get a copy of this message
I'm guessing that you have to swap every other byte as Windows is the other-endian... I don't really know for sure though... You could just use: exec("/path/to/sox $infile $outfile", $results, $errorcode); echo implode("<BR>\n", $results); if ($errorcode){ echo "OS Error $errorcode. Usually path/permission. man errno<BR>\n"; } -- WARNING richard@zend.com address is an endangered species -- Use ceo@l-i-e.com Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm ----- Original Message ----- From: Jason Mercer <jasonmercer@yahoo.com> Newsgroups: php.general To: <php-general@lists.php.net> Sent: Tuesday, August 28, 2001 9:13 PM Subject: perl-esque data parsing for hex post variables > I can't get the php to convert audio data to nicely formed binary wav > format. For instance, in perl you simply do a > > $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; > > and you're done with it. > > In php, there are two problems: > > 1. no existence of a handy builtin hex2bin() function (though many have been > written, such as > > function hex2bin($hex_str) > > > for ($i = 0; $i < strlen($hex_str); $i += 2) > > > $bin_str .= chr(hexdec(substr($hex_str, $i, 2))); > > } > > return $bin_str; > > } > > which seems to get the case done, > > 2. But the real problem is that doing a straight hex2bin conversion is not > what that beautiful little perl script does. The part that confuses me is > the hash oriented piece /%([a-fA-F0-9][a-fA-F0-9])/ -- what exactly is it > doing? Is it just stepping through the string two characters at a time and > comparing them? Or is it doing something more ambitious and arcane that I'm > not really grasping. I tried to emulate it with the following php > workaround, but come up short... > > for ($i = 0; $i < strlen($hex_str); $i += 2) > > > $newdata =. > preg_replace("/[a-fA-F0-9][a-fA-F0-9]/",pack("C",hexdec(substr($hex_str, $i, > 2))),$hex_str); > > } > > Any help? > > >

« previous php.general (#65239) next »