php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #14523 Additional parameter for str_repeat()
Submitted: 2001-12-14 14:14 UTC Modified: 2021-05-26 11:32 UTC
Votes:12
Avg. Score:2.7 ± 1.4
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:3 (75.0%)
From: ahristov at icygen dot com Assigned:
Status: Wont fix Package: Strings related
PHP Version: * OS: *
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: ahristov at icygen dot com
New email:
PHP Version: OS:

 

 [2001-12-14 14:14 UTC] ahristov at icygen dot com
Is is possible third parameter to be added to str_repeat().
In case in the string there is a name of a variable and it is of type array the following code :
foreach ($some_arr as $k =$v){
  $output .= '<some_html>...'.$v.'....</some_html>';
}
to be in one line
$output = str_repeat('<some_html>...$some_arr ...</some_html>',count($some_arr),REPEAT_SUBSITUTE);

Regards,
Andrey Hristov

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-31 11:25 UTC] andrey@php.net
better will be done with :
<?php
$a = array("one", "two", "three");
$s = "[text]";

echo str_replace(array('text'), array_values($a), str_repeat($s, 10));
?>

but this doesn't work.
So, reclassifying as feature request for str_replace().
"str_replace() should behave differently when string is used as [search] and array is passed as [replace]".

Pollita, any comment on that. If that will break BC, then we will "won't fix" this.
Thanks.
 [2003-08-26 19:14 UTC] pollita@php.net
oops, didn't notice this was assigned to me.

I don't see that breaking BC since the current behavior is to convert $replace to a string if $search is not an array, hence str_replace('search',array('re','place'),'search my search for a search') would be a new condition to be handled.

The only behavior I see this breaking is those who expect the above to return 'Array my Array for a Array' (which is a pretty esoteric behavior), would now get 're my place for a re'

If you can get a concensus from php.internals, then it shouldn't be terribly hard to implement.
 [2010-12-20 13:32 UTC] jani@php.net
-Summary: Additional parameter for str_repeat +Summary: Additional parameter for str_repeat() -Package: Feature/Change Request +Package: Strings related -PHP Version: 4.1.0 +PHP Version: *
 [2010-12-20 13:32 UTC] jani@php.net
-Operating System: +Operating System: *
 [2016-01-16 00:09 UTC] francois@php.net
-Assigned To: pollita +Assigned To: francois
 [2016-01-16 00:09 UTC] francois@php.net
The 'Add cyclic string replacements' RFC (https://wiki.php.net/rfc/cyclic-replace) implements str_replace(search=<string>, replace=<array>). This RFC targets version 7.1.
 [2017-10-22 23:41 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: francois +Assigned To:
 [2017-10-22 23:41 UTC] kalle@php.net
Since francois' RFC has been Abandoned, I'm gonna unassign him this report
 [2017-10-23 00:12 UTC] kalle@php.net
-Status: Open +Status: Analyzed
 [2021-05-26 11:32 UTC] krakjoe@php.net
-Status: Analyzed +Status: Wont fix
 [2021-05-26 11:32 UTC] krakjoe@php.net
Since I closed the RFC PR several years ago, and no new RFC was started, I think it's safe to assume that 20 years after this FR was opened, that we are not going to implement this feature.

This report remains for reference but will be marked won't fix, as that more accurately represents the current status than does open.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC