PHP - str_replace example

Syntax
    
    str_replace($find, $replace, $string, $count)
    
Example 1
    
    $string = 'Hello world!';
    $find = 'world!';
    $replace = 'foo bar!';
    $result = str_replace($find, $replace, $string);
    echo $result;
    // output
    // Hello foo bar
    
Example 2
    
    $string = 'Hello world!';
    $find = 'o';
    $replace = '';
    $result = str_replace($find, $replace, $string, $count);
    print_r($count);
    // output
    // 2
    

Comments