[ create a new paste ] login | about

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

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

    echo $str;
    $i = 1;
    while (($offset = strpos($str, $old)) !== false) {
      $str = substr_replace($str, $new . ($i++), $offset, strlen($old));
    }
    echo PHP_EOL;
    echo $str;


Output:
1
2
Old string Old more string Old some more string
New1 string New2 more string New3 some more string


Create a new paste based on this one


Comments: