[ create a new paste ] login | about

Link: http://codepad.org/gSae4Bkd    [ raw code | output | fork ]

PHP, pasted on Jul 6:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
$str = 'Old string Old more string Old some more string';
$old = 'Old';
$new = 'New';

$olds = Array();
$news = Array();
$n = substr_count($str, $old);
for ($i = 0; $i < $n; $i++) {
   $olds[] = $old;
   $news[] = $new . ($i+1);
}

echo str_replace($olds, $news, $str);
?>


Output:
1
New1 string New1 more string New1 some more string


Create a new paste based on this one


Comments: