php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1495 substr gets confused when used with strlen is the best way I can describe it.
Submitted: 1999-06-05 15:46 UTC Modified: 1999-06-05 15:55 UTC
From: richard at vasquez dot net Assigned:
Status: Closed Package: Parser error
PHP Version: 3.0.6 OS: Linux
Private report: No CVE-ID: None
 [1999-06-05 15:46 UTC] richard at vasquez dot net
Here's a script that reproduces the problem.  The first output shows the bug, as far as I can see.  The second output shows how it should be.  If you look at the output, the problem only occurs during the first few numbers in a sequence which makes me think it's a bug.  ie, 0, 1, 2 come out as 00, 01, 02, while 3 on up (until 100, where the bug reoccurs) come out as 003, etc.

The only modules I have configured in are gd and mysql.  PHP is running as an Apache (1.3.3) module.

<?
   for($loop=0; $loop <110; $loop++)
   {
      $tmpidx="000$loop";
      $orig=$tmpidx;
      $tmpidx=substr($tmpidx, strlen($tmpidx-3), 3);

      echo "$loop: $tmpidx ($orig)<BR>\n";
   }
?>
<HR>
<?
   for ($loop=0; $loop <110; $loop++)
   {
      $tmpidx="00$loop";
      $orig=$tmpidx;
      $tmplen=strlen($tmpidx)-3;
      $tmpidx=substr($tmpidx, $tmplen, 3);

      echo "$loop: $tmpidx ($orig)<BR>\n";
   }
?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-06-05 15:55 UTC] andrey at cvs dot php dot net
Your script is wrong.

$tmpidx=substr($tmpidx, strlen($tmpidx-3), 3);

should be

$tmpidx=substr($tmpidx, strlen($tmpidx)-3, 3);
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Mar 03 16:01:28 2024 UTC