|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #71453 sscanf() ignores format text after string placeholder
Submitted: 2016-01-26 11:14 UTC Modified: 2016-01-31 15:23 UTC
From: dormilich at netscape dot net Assigned:
Status: Open Package: *General Issues
PHP Version: 5.6.17 OS: Mac OS X (10.11.3)
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2016-01-26 11:14 UTC] dormilich at netscape dot net
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:
sscanf('<report>cf2b27b5556c2ddc</report>', '<report>%s</report>', $hex);
echo $hex;

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-01-28 15:02 UTC] dormilich at netscape dot net
this bug occurs for every string placeholder, not just the last one.
 [2016-01-31 15:23 UTC]
-Type: Bug +Type: Documentation Problem
 [2016-01-31 15:23 UTC]
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().
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Oct 27 04:01:24 2020 UTC