A little confused about sscanf() and formatting.

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
typewriter
Forum Newbie
Posts: 7
Joined: Tue Sep 26, 2006 4:50 pm

A little confused about sscanf() and formatting.

Post 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]
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

Have not clue about this but from php.net show $n = before the sscanf

so try changing it to $n = sscanff....
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

%s will read to the next space, end-of-line or end of string, which ever comes first.
Post Reply