note 68565 added to function.sscanf
| From: | anonymouse at osu1 dot php dot net | Date: | Wed, 02 Aug 2006 04:38:58 +0000 |
| Subject: | note 68565 added to function.sscanf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115434@lists.php.net to get a copy of this message | ||
I've seen several examples of people using brackets to define what look like regexp character
classes. In my limited testing I don't think they are genuine character classes but they seem
to be similar.
My task was to use sscanf() to parse an array of strings with the format:
number SPACE string_which_may_also_have_spaces
The normal %s conversion command treats spaces as some kind of delimiter. So, you can get the
strings if you know beforehand how many "words" there will be. But, my input was variable.
Here's what I came up with: (note use of the dollar-sign 'end of string' hidden
delimiter)
sscanf($string_to_parse,'%d %[^$]s',$num,$text);
This conversion command says "look for an integer, then a space, then any string up to the end
of the string"
----
Server IP: 64.71.164.2
Probable Submitter: 162.84.180.120
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.sscanf.php
Edit -- https://master.php.net/note/edit/68565
Del: integrated -- https://master.php.net/note/delete/68565/integrated
Del: useless -- https://master.php.net/note/delete/68565/useless
Del: bad code -- https://master.php.net/note/delete/68565/bad+code
Del: spam -- https://master.php.net/note/delete/68565/spam
Del: non-english -- https://master.php.net/note/delete/68565/non-english
Del: in docs -- https://master.php.net/note/delete/68565/in+docs
Del: other reasons-- https://master.php.net/note/delete/68565
Reject -- https://master.php.net/note/reject/68565
Search -- https://master.php.net/manage/user-notes.php