php str_replace – The Best PHP 3 Examples

Today, We want to share with you php str_replace.In this post we will show you PHP string replace regex, hear for Substr PHP we will give you demo and example for implement.In this post, we will learn about String Replace PHP Functions with an example.

php str_replace

Example : 1 str_replace() Function

<!DOCTYPE html>
<html>
<body>

<p>Search the string "Welcome Pakainfo!", find the value "Pakainfo" and replace it with "online":</p>

<?php
echo str_replace("Pakainfo","online","Welcome Pakainfo!");
?>

</body>
</html>

Example : 2

<?php
  
// Input string
$market  = "You products daskptop, mobiles, laptop every day.";
  
// Array containing search string 
$searchVal = array("daskptop", "mobiles", "laptop");
  
// Array containing replace string from  search string
$replaceVal = array("dvd", "pendrive", "mini mac");
  
// Function to replace string
$res = str_replace($searchVal, $replaceVal, $market);
  
print_r($res);
?>

Example : 3 Use the str_replace() function

<!DOCTYPE html>
<html lang="en">
<head>
    <title>PHP Replacing Text within a String</title>
</head>
<body>

<?php
$market_str = 'If the products do not fit the articles, update the products.';
 
// Display replaced string
echo str_replace("products", "truth", $market_str);
?>

</body>
</html>

Free Live Chat for Any Issue

I hope you get an idea about php str_replace.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, donโ€™t forget to share.