Doc #71453 [Opn->Csd]: sscanf() ignores format text after string placeholder

From: Date: Wed, 13 Jan 2021 14:55:32 +0000
Subject: Doc #71453 [Opn->Csd]: sscanf() ignores format text after string placeholder
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-18383@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: cmb@php.net Reported by: dormilich at netscape dot net Summary: sscanf() ignores format text after string placeholder -Status: Open +Status: Closed Type: Documentation Problem Package: *General Issues Operating System: Mac OS X (10.11.3) PHP Version: 5.6.17 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: This has been fixed[1] in the meantime. [1] <https://github.com/php/doc-en/commit/34bec0531adc622a950f30029cf6d54d98e7f8d4> Previous Comments: ------------------------------------------------------------------------ [2016-01-31 15:23:49] 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(). ------------------------------------------------------------------------ [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

« previous php.doc.bugs (#18383) next »