Page 1 of 1

A little confused about sscanf() and formatting.

Posted: Mon Mar 05, 2007 6:09 pm
by typewriter
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I have looked at some examples for sscanf, but I can't tell what I'm doing wrong.

Code: Select all

$c=">32>wolf>canine>mammal>animal";
sscanf($c,'>%d>%s>%s>%s>%s', $v1,$v2,$v3,$v4,$v5);
var_dump($v1,$v2,$v3,$v4,$v5);
The output is:

int(32) string(25) "wolf>canine>mammal>animal" NULL NULL NULL

But I would like "wolf" "canine" "mammal" and "animal" to be separated into the $v2,$v3,$v4 and $v5 variables.

I'm sure I'm missing a basic concept of format characters. Can anyone
assist me? Thanks very much!


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Mar 05, 2007 6:49 pm
by tecktalkcm0391
Have not clue about this but from php.net show $n = before the sscanf

so try changing it to $n = sscanff....

Posted: Mon Mar 05, 2007 9:17 pm
by feyd
%s will read to the next space, end-of-line or end of string, which ever comes first.