PHP Programing language

str_replace() Function in PHP
Previous Home Next

str_replace()

The str_replace() function replaces some characters with some other characters in a string. This function works by the following rules:

  1. If the string to be searched is an array, it returns an array.
  2. If the string to be searched is an array, find and replace is performed with every array element.
  3. If both find and replace are arrays, and replace has fewer elements than find, an empty string will be used as replace.
  4. If find is an array and replace is a string, the replace string will be used for every find value.
Syntax :
str_replace("search","replace","string/array",["count"]);

 

Example:

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

Output:

Hello India!

In the above example you search the string Hello world and world string replaces by India. Thus the result output is Hello India!
Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: