note 23145 deleted from function.sscanf by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 09:03:09 +0000 |
| Subject: | note 23145 deleted from function.sscanf by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-196858@lists.php.net to get a copy of this message | ||
Note Submitter: jamesDOTwatsonATrealismstudiosDOTcom
----
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;