![]()  | 
| Replace Multiple String In PHP | 
In this case you have to know a PHP function which is call "str_replace", the below code will explain you how it work.
function replace_multiple_string($search=array(),$replace="",$string="")
{
  if(count($search) < 1)
  {
    return false;
  }
  else
  {
    return str_replace($search, $replace, $string);
  }
}
Explanation:
- str_replace : Replace all occurrences of the search string with the replacement string.
Usage :
$string= "You are on_tip(and)php+website";
$search= array("_", "(", "+", ")"," ","+");
var_dump(replace_multiple_string($search,"-",$string));
Demo :
string(29) "You-are-on-tip-php-website"

0 comments:
Post a Comment