php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #21318 str_pad will pad even if input_len + pad_str_len > pad_length
Submitted: 2003-01-01 05:35 UTC Modified: 2003-07-05 01:43 UTC
From: jc at mega-bucks dot co dot jp Assigned: hholzgra (profile)
Status: Closed Package: Documentation problem
PHP Version: 4.3.0 OS: Linux
Private report: No CVE-ID: None
 [2003-01-01 05:35 UTC] jc at mega-bucks dot co dot jp
str_pad pad the input string even when the length of the pad string cannot be evenly dived into the length of the input stirng + pad_length.

This is not necessarily a bug but the behaviour should be documented. I.e. in some cases the user might want the string be padded only with *full-length* pad strings, and not truncated pad strings. 

The following code illustrates:

echo str_pad("1", 2, "AB");

OUPUT:

1A

The output could be viewed as "incorrect" since pad_str was aksed to pad with "AB", not to pad with "A".

Thanks!

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-04 17:08 UTC] hholzgra@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 [2003-07-04 21:33 UTC] jc at mega-bucks dot co dot jp
Could you state *how* the bug was fixed? i.e. was the behaviour of the function changed or was the documentation changed to explain the current behaviour?

Thanks!
 [2003-07-05 01:43 UTC] derick@php.net
It was closed as a "documentation problem", so it was fixed in the docs.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 14 14:01:31 2025 UTC