note 13881 added to function.fscanf.php

From: Date: Sun, 08 Jul 2001 04:29:41 +0000
Subject: note 13881 added to function.fscanf.php
Groups: php.notes 
Request: Send a blank email to php-notes+get-15084@lists.php.net to get a copy of this message
fscanf works a little retardedly I've found. Instead of using just a plain %s you probably will need to use sets instead. Because it works so screwy compared to C/C++, fscanf does not have the ability to scan ahead in a string and pattern match correctly, so a seemingly perfect function call like: fscanf($fh, "%s::%s"); With a file like: user::password Will not work. When fscanf looks for a string, it will look and stop at nothing except for a whitespace so :: and everything except whitespace is considered part of that string, however you can make it a little smarter by: fscanf($fh, "%[a-zA-Z0-9,. ]::%[a-zA-Z0-9,. ]" $var1, $var2); Which tells it that it can only accept a through z A through Z 0 through 9 a comma a period and a whitespace as input to the string, everything else cause it to stop taking in as input and continue parsing the line. This is very useful if you want to get a sentence into the string and you're not sure of exactly how many words to add, etc. http://www.php.net/manual/en/function.fscanf.php

« previous php.notes (#15084) next »