Re: fscanf

From: Date: Mon, 12 Mar 2001 11:00:01 +0000
Subject: Re: fscanf
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-43450@lists.php.net to get a copy of this message
"Kubol" <kubol@kormoran.trzepak.pl> wrote in message news:200103112020.f2BKKbf27786@kormoran.trzepak.pl... > hello > > if this is really a silly problem dont blame me, i'm a newbie in php (but i'm experienced in c++ a bit :-) > well, imagine i want to write a content of some text file word by word. example will be more understandable > than my english: > let file.txt consists: > lenin lives > forever > i want my php script to write to the screen: > lenin > lives > forever > I tried to manage this using fscanf function. i expected it works same as in c, but it looks it doesnt. consider > the code: > while (fscanf($file,"%s",$buffer)==1) > { > echo $buffer,"<br>"; > } > the result: > lenin > forever > just like fscanf moved the file pointer to the next line after reading "lenin". i dont know whats up... why "lives" > disappeared??? i know i can try using fgets and then split the string, but i want to know why fscanf doesnt > work... :-) > could anyone explain me this phenomena? I think fscanf() is line oriented in C, isn't it? (I haven't used fscanf() for a long time, I'm not 100% sure w/o reference.) "%s" format in fscanf() and sscanf() will macthes sequecne of non-white-space charactors in C and PHP. Your $buffer should only have "lenin". So if you write like while (fscanf($file,"%s %s",$buf1,buf2)) You should get "lives" in $buf2. Regards, Yasuo Ohgaki > > best regards, > jakub zytka > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#43450) next »