Tuesday, 17 November 2015

13_str_replace()

str_replace()


< ? php
$string= “Harshida, This is a String. And is an example.”;
$new_str=str_replace(“is”,””,$string);
Echo $new_str; ? >


1st para:- is replace value, 2nd para:- Replace by NULL “WHITE SPACE”, 3rd para:- String name.


O/P :- > Harshida, Th a string, AND an example.


Now if we want to replace ONE VALUE ON MORE THAN ONE WORD… LIKE WE WAN TO REPALCE “HARSHIDA”, “string”,”example” TO “” (WHITE SPACE)


< ? php
$find1=array(“HARSHIDA”,”string”,”example”);
$string= “Harshida, This is a String. And is an example.”;
$new_str=str_replace($find1,””,$string);
Echo $new_str; ? >


you can see that our array $find1 contain three value and this three value is going to be replace by “” (WHITE SPACE).


NOW we want to replace the 3 different word with 3 different value then


< ? php
$find1=array(“HARSHIDA”,”string”,”example”);
$replace1=array(“harshida”,”STRING”,”EXAMPLE”);
$string= “Harshida, This is a String. And is an example.”;
$new_str=str_replace($find1,$replace1,$string);
Echo $new_str; ? >


So here you can see that in str_replace() function $find1 array variable first value HARSHIDA Is replace by $replace1 array variable First value and so on…



No comments:

Post a Comment