Bug->Doc #71453 [Opn]: sscanf() ignores format text after string placeholder
| From: | bwoebi@php.net | Date: | Sun, 31 Jan 2016 15:23:50 +0000 |
| Subject: | Bug->Doc #71453 [Opn]: sscanf() ignores format text after string placeholder | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-13152@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71453&edit=1
ID: 71453
Updated by: bwoebi@php.net
Reported by: dormilich at netscape dot net
Summary: sscanf() ignores format text after string
placeholder
Status: Open
-Type: Bug
+Type: Documentation Problem
Package: *General Issues
Operating System: Mac OS X (10.11.3)
PHP Version: 5.6.17
Block user comment: N
Private report: N
New Comment:
Marking as doc problem as it actually doesn't document that %s is greedy and will only halt on
whitespaces (or null-byte or string end) and doesn't backtrack (unlike regex).
But behavior is intentional.
For your usage case, use preg_match().
Previous Comments:
------------------------------------------------------------------------
[2016-01-28 15:02:20] dormilich at netscape dot net
this bug occurs for every string placeholder, not just the last one.
------------------------------------------------------------------------
[2016-01-26 11:14:05] dormilich at netscape dot net
Description:
------------
When the format string contains text after the last placeholder, which must be a string (i.e. %s),
the variable is not only assigned the intended value, but also the text coming after it.
Test script:
---------------
<?php
sscanf('<report>cf2b27b5556c2ddc</report>',
'<report>%s</report>', $hex);
echo $hex;
?>
Expected result:
----------------
cf2b27b5556c2ddc
Actual result:
--------------
cf2b27b5556c2ddc</report>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71453&edit=1