You are here: Re: [PHP] trying to understand PHP unpack(); « PHP « IT news, forums, messages
Re: [PHP] trying to understand PHP unpack();

Posted by Jochem Maas on 08/01/05 23:29

Sonia wrote:
> Hi
>
> In Perl I have a part of a script....
>
> # cut..
>
> my $line = '!v2005*08|05+09?04^19*!';
^-- note how my email client screws up your original
string... something I don't really understand...
>
> my ( $s_code, $year, $month, $day, $hour, $minute, $second, $e_code ) =
> unpack ( "x1 A1 A4 x1 A2 x1 A2 x1 A2 x1 A2 x1 A2 A1", $line );
>
> print $s_code . "\n";
> print $year . "\n";
> print $month . "\n";
> print $day . "\n";
> print $hour . "\n";
> print $minute . "\n";
> print $second . "\n";
> print $e_code . "\n";
>
> sleep 10; # so we can see it in the command window
>
>
>
> In Perl this runs without trouble, in PHP it does not seem to work the same
> way. Can someone explain to me what I need to do differently to
> allow PHP to understand what I am trying to do!
>
> <?
>
> my $line = '!v2005*08|05+09?04^19*!';
^-- this will cause a parse error

>
> $output = unpack ( "x1 A1 A4 x1 A2 x1 A2 x1 A2 x1 A2 x1 A2 A1", $line );
>
> print_r ( $output );
>
> ?>

I have next no knowledge wroth speaking of concerning binary data - and the
string screw problem mentioned above makes it impossible for me to determine whether
I am really on the right path here but take a look at the following:

$line = "!v2005*08|05+09?0419*!";
$output = unpack ( "x1 A1 A4 x1 A2 x1 A2 x1 A2 x1 A2 x1 A2 A1", $line );
$output2 = unpack ( "x1A1A4x1A2x1A2x1A2x1A2x1A2A1", $line );
$output3 = unpack ( "x1/A1/A4/x1/A2/x1/A2/x1/A2/x1/A2/x1/A2/A1", $line );
$output4 = unpack ( "x1_a/A1_b/A4_c/x1_d/A2_e/x1_f/A2_g/x1_h/A2_i/x1_j/A2_k/x1_l/A2_m/A1_n", $line );
var_dump( $output, $output2, $output3, $output4 );'

this page:
http://nl2.php.net/unpack

.... does mention that the php unpack() implementation is somewhat different to the perl one
(btw I'm a complete perl luddite! - I don't think my brain can cope with that much cryptic crap
;-) - that said thank Larry for PCRE!)

I'd be very grateful if you report back on your progress - I for one can definitely learn something
here!

rgds,
jochem

ps - welcome to phpland perlie ;-)

>
>
> Thanks
>
> SD
>

 

Navigation:

[Reply to this 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

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