note 78593 added to function.sscanf

From: Date: Thu, 18 Oct 2007 14:12:53 +0000
Subject: note 78593 added to function.sscanf
Groups: php.notes 
Request: Send a blank email to php-notes+get-131494@lists.php.net to get a copy of this message
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. ---- Server IP: 69.147.83.197 Probable Submitter: 71.48.197.132 ---- Manual Page -- http://www.php.net/manual/en/function.sscanf.php Edit -- https://master.php.net/note/edit/78593 Del: integrated -- https://master.php.net/note/delete/78593/integrated Del: useless -- https://master.php.net/note/delete/78593/useless Del: bad code -- https://master.php.net/note/delete/78593/bad+code Del: spam -- https://master.php.net/note/delete/78593/spam Del: non-english -- https://master.php.net/note/delete/78593/non-english Del: in docs -- https://master.php.net/note/delete/78593/in+docs Del: other reasons-- https://master.php.net/note/delete/78593 Reject -- https://master.php.net/note/reject/78593 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#131494) next »