PHP String Functions

str_replace() Function

Definition and Usage

The str_replace() function replaces some characters with some other characters in a string.

Note:
  • This function is case-sensitive. Use the str_ireplace() function to perform a case-insensitive search.

  • Syntax

    str_replace(find,replace,string,count)


    Parameter Description
    find Required. Specifies the value to find
    replace Required. Specifies the value to replace the value in find
    string Required. Specifies the string to be searched
    count Optional. A variable that counts the number of replacements

    Example

    Replace the characters "world" in the string "Hello world!" with "Falguni":

    <?php
    echo str_replace("world","Peter","Hello world!");
    ?>

    Run Example>>