I'm trying to sscanf
to read a bunch of successive fixed length strings but it's not working very well. I can print a fixed length string thusly:
sprintf('%.5s', 'aaaaabbbbb');
But if I try to use %.5s
to read a fixed length string (eg. the first 5 bytes of an input string) it doesn't work. eg.
var_dump(sscanf('aaaaabbbbb', '%.5s'));
If I do that var_dump
returns NULL
and I get the following Warning:
Warning: sscanf(): Bad scan conversion character "."
I tried %5s
in addition to %.5s
but that doesn't work as desired either. eg.
var_dump(sscanf('aa aabbbbb', '%5s'));
That returns this:
array(1) {
[0]=>
string(2) "aa"
}
What I'd want it to return is this:
array(1) {
[0]=>
string(5) "aa aa"
}
Any ideas?