# for replace someting in string use this function
# str_replace("1st param for select","2nd param for replace with","3rd your string")
<?php$string=str_replace(" ","_","Hello World");// Output will be : Hello_world?>
$phrase="You should eat fruits, vegetables, and fiber every day.";$healthy=array("fruits","vegetables","fiber");$yummy=array("pizza","beer","ice cream");$newphrase=str_replace($healthy,$yummy,$phrase);// => $newphrase = You should eat pizza, beer, and ice cream every day
phpCopy<?php$mystring="This is my string.";echo("This is the string before replacement: ");echo($mystring);echo("
");$mynewstring=str_replace(" my "," ",$mystring);echo("Now, this is the string after replacement: ");echo($mynewstring);?>
phpCopy<?php$mystring="This is my string.";echo("This is the string before replacement: ");echo($mystring);echo("
");$mynewstring=str_replace(" my "," ",$mystring,$count);echo("Now, this is the string after replacement: ");echo($mynewstring);echo("
");echo("The number of replacements is: ");echo($count);?>
<?php$var='ABCDEFGH:/MNRPQR/';echo"Original: $var<hr />
";/* These two examples replace all of $var with 'bob'. */echosubstr_replace($var,'bob',0)."<br />
";echosubstr_replace($var,'bob',0,strlen($var))."<br />
";/* Insert 'bob' right at the beginning of $var. */echosubstr_replace($var,'bob',0,0)."<br />
";/* These next two replace 'MNRPQR' in $var with 'bob'. */echosubstr_replace($var,'bob',10,-1)."<br />
";echosubstr_replace($var,'bob',-7,-1)."<br />
";/* Delete 'MNRPQR' from $var. */echosubstr_replace($var,'',10,-1)."<br />
";?>
PHP substr_replace — Replace text within a portion of a string
<?php$var='ABCDEFGH:/MNRPQR/';echo"Original: $var<hr />
";/* These two examples replace all of $var with 'bob'. */echosubstr_replace($var,'bob',0)."<br />
";echosubstr_replace($var,'bob',0,strlen($var))."<br />
";/* Insert 'bob' right at the beginning of $var. */echosubstr_replace($var,'bob',0,0)."<br />
";/* These next two replace 'MNRPQR' in $var with 'bob'. */echosubstr_replace($var,'bob',10,-1)."<br />
";echosubstr_replace($var,'bob',-7,-1)."<br />
";/* Delete 'MNRPQR' from $var. */echosubstr_replace($var,'',10,-1)."<br />
";?>