PHP str_replace() string function

The str_replace() function in PHP

The str_replace() function used to replace one string with some another string.

str_replace() function syntax

str_replace(“search for”, “replace”, “original string”);

PHP str_replace() function example

echo "Replaced Hello = ". str_replace("Hello", "Academy","Hello Meera Academy");

The str_replace() function output is

Replaced string = Academy Meera Academy

In above example the word “hello” replaced by “academy” so out put new string is “Academy Meera Academy”.

php example of str_replace string function.

<title>PHP str_replace() Function</title>

<FORM method="POST" action="firstexample.php">

Name : <input type="text" name="name"> <br/>

<input type="submit" name="Submit1" value="String Replace">


echo "Replaced Hello = ". str_replace("Hello", "Academy",$_POST["name"]);


PHP str_replace string function example out put screen like:

PHP str_replace() string fuction
PHP str_replace() string fuction

In above string function example we input “Hello Meera Academy” text in textbox and the word “Hello” replaced by word “Academy” using str_replace php string function.

Leave a Reply

Your email address will not be published. Required fields are marked *