note 23145 added to function.sscanf

From: Date: Wed, 10 Jul 2002 16:31:30 +0000
Subject: note 23145 added to function.sscanf
Groups: php.notes 
Request: Send a blank email to php-notes+get-32848@lists.php.net to get a copy of this message
You're making a common mistake in believing that sscanf (and the whole scanf family) are more intelligent than they really are, sscanf always starts checking from the first character of the string, the first character that doesn't match the format string causes it to bail out early, if you want to match later in the string you'll have to do something like this: sscanf(strstr($lit[$x],"Vol."),"Vol. %d",&$vol[$x]); (check the docs on strstr if you're unsure of how it works) or if you want you can add some simple error correction $temp=strstr($lit[$x],"Vol."); if ($temp) sscanf($temp,"Vol. %d",&$vol[$x]); else $vol[$x]=$default_vol; -- http://www.php.net/manual/en/function.sscanf.php http://master.php.net/manage/user-notes.php?action=edit+23145 http://master.php.net/manage/user-notes.php?action=delete+23145 http://master.php.net/manage/user-notes.php?action=reject+23145

« previous php.notes (#32848) next »