php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32989 str_pad and str_repeat return wrong string
Submitted: 2005-05-09 17:10 UTC Modified: 2005-05-09 18:56 UTC
From: gclift at gtsquared dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 4.3.11 OS: Linux 2.4.21-27.0.2.ELsmp #1
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: gclift at gtsquared dot com
New email:
PHP Version: OS:

 

 [2005-05-09 17:10 UTC] gclift at gtsquared dot com
Description:
------------
str_pad returns the exact same string that was entered as the string input.

str_repeat returns 0 length string.


'./configure' '--localstatedir=/var/hsphere/php' '--with-apxs=/hsphere/shared/apache/bin/apxs' '--with-openssl=/usr' '--with-zlib=/usr' '--with-zlib-dir=/usr' '--with-bz2=/usr' '--enable-calendar' '--with-jpeg-dir=/usr' '--enable-ftp' '--with-gd' '--with-ttf' '--with-freetype-dir=/usr' '--enable-gd-native-ttf' '--with-png-dir=/usr' '--with-gettext=/usr' '--with-imap=/hsphere/shared' '--with-mysql=/usr' '--with-pgsql=/usr' '--with-curl=/hsphere/shared' '--with-curlwrappers' '--with-mhash=/usr' '--with-iconv=/hsphere/shared' '--enable-sockets' '--with-zip=/usr' '--enable-versioning' '--enable-track-vars' '--enable-trans-sid' '--enable-bcmath' '--enable-mbstring' '--disable-debug'

Reproduce code:
---------------
<?php
echo "<br>Start Test!<br>";
echo "<pre>";

var_dump( str_repeat(4, "../") );
echo "\r\n";
var_dump( str_pad("TESTING", 6, "../", STR_PAD_LEFT) );
echo "\r\n";
var_dump( str_pad("TESTING", 6, "-==") );
echo "\r\n";
var_dump( str_pad("TEST", 4) );

echo "</pre>";
echo "<br>End Test!<br>";
exit(0);


?>

Expected result:
----------------
Start Test!

string(0) "../../../../"

string(7) "../../../../../TESTING"

string(7) "TESTING-==-==-==-==-==-=="

string(4) "TEST    "


End Test!

Actual result:
--------------
Start Test!

string(0) ""

string(7) "TESTING"

string(7) "TESTING"

string(4) "TEST"


End Test!

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-05-09 18:56 UTC] derick@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

Read the manual again, pay close attention to the examples and the order of parameters.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 11:01:30 2024 UTC