note 78593 rejected from function.sscanf by nlopess
| From: | nlopess@php.net | Date: | Wed, 31 Oct 2007 21:24:15 +0000 |
| Subject: | note 78593 rejected from function.sscanf by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-131886@lists.php.net to get a copy of this message | ||
Note Submitter: lord_dakron at hotmail dot com
----
Apparently sscanf is completely broken in PHP 4 and 5, and has been since I started using PHP in
version 3. In every other language you call sscanf with a format string, but in PHP I have
discovered that you can only limit variables with spaces. For example:
<?php
$MyString = "FirstName LastName-Email@Address.net";
list($Name, $Email) = sscanf($MyString, "%s-%s");
?>
This sets $Email to NULL and $Name to "FirstName". Now let's try it another way.
<?php
$MyString = "FirstName-LastName-Email@Address.net";
list($First, $Last, $Email) = sscanf($MyString, "%s-%s-%s");
?>
This sets $First to "FirstName-LastName-Email@Address.net" and the other two to NULL. The
function only seems to pay attention to spaces and does NOT work properly. The best bet for a
veteran programmer who has used sscanf in other languages such as C or C++ is to write a custom
parasing function that scans strings one character at a time and parses it out itself.