php.net |  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dormilich at netscape dot net
New email:
PHP Version: OS:

 

 [2016-01-26 11:14 UTC] 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>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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] bwoebi@php.net
-Type: Bug +Type: Documentation Problem
 [2016-01-31 15:23 UTC] bwoebi@php.net
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-2019 The PHP Group
All rights reserved.
Last updated: Sun Jul 21 09:01:26 2019 UTC