#69. PHP String Replace Functions

 How to work PHP String Replace Functions?

Syntax & E.g.



Run Code:
<?php

$str = "I love Programming. I am a Programmer";

$find = ["I","love", "Programming"];
$replace = ["","Hi","Programmer"];

echo str_replace("love", " ", $str);

echo str_replace($find, $replace, $str);

str_ireplace case-insensitive
echo str_ireplace($find, $replace, $str);
?>


Run Code:
<?php

$str = "I love Programming. I am a Programmer";

// $find = ["I","love", "Programming"];
// $replace = ["","Hi","Programmer"];

//$array = ["Civic","Corola","Alto"];


//substr_replace
//echo substr_replace($str, "Programmer",7,13);

// Replace in Array function
// echo "<pre>";
// print_r(str_replace("Civic", "Sazuki",$array));
// echo "</pre>";

?>


Run Code:

<?php

$str = "I love Programming. I am a Programmer";


// we also use Associative array function
//strtr
echo strtr($str, "ve", "ly");


?>

Comments

Popular posts from this blog

#30. PHP Recursive Function