sscanf() ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

sscanf() ?

Post by Chris Corbyn »

I'm not an expert on the whole behaviour of printf() and friends, but should I give up trying to achieve this?

Code: Select all

list ($type, $value) = sscanf("string:foobar", "%s:%s");
$value is always NULL and $type is the entire string, including the colon :(

I'm currently using substr() but spotted this cool looking function in the manual. Will it always be too greedy?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: sscanf() ?

Post by Chris Corbyn »

Answered my own question :P

Code: Select all

list($type, $value) = sscanf($string, "%[^:]:%s");
Post Reply