I need to split a string into chunks of 2,2,3,3 characters and was able to do so in Perl by using unpack:
unpack("A2A2A3A3", 'thisisloremipsum');
However the same function does not work in PHP, it gives this output:
Array
(
[A2A3A3] => th
)
How can I do this by using unpack? I don't want to write a function for it, it should be possible with unpack but how?
Thanks in advance,
I've never used this function, but according to the documentation, the
A
character means "SPACE-padded string". So I'd hazard a guess that it's only taking the first two characters of the first word.Have you tried
unpack("A2A2A3A3", 'this is lorem ipsum');
?Quoting the manual page of
unpack
:Which means that, using something like this :
You'll get the following output :