php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43467 function substr() does not function the same
Submitted: 2007-12-01 08:50 UTC Modified: 2007-12-02 16:05 UTC
From: mgd at xpressbillpay dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.2.5 OS: Windows XP and server 2003
Private report: No CVE-ID: None
 [2007-12-01 08:50 UTC] mgd at xpressbillpay dot com
Description:
------------
script using substr($strVal, -10);
if $strVal length is less then 10 chars (or less then int start) the return value is empty.

In a previous version(I had 5.1.4 before upgrade) substr($strVal, -10); would still return the full #strVal if less then 10 which it should since int start should begin from the last character and count back x number of chars and stop at the first if $strVal is less the the count.


Reproduce code:
---------------
<?PHP
$str = "1234567";
echo substr($str,-8);
?>

Expected result:
----------------
1234567

Actual result:
--------------
empty

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-01 11:28 UTC] felipe@php.net
Anyway, says the documentation:
"If start denotes a position beyond this truncation, an empty string will be returned."
 [2007-12-02 16:05 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Aug 17 03:00:03 2025 UTC