PHP Replace String with Another String Example

Nov 25, 2022

.

Admin

PHP Replace String with Another String Example

Hi Dev,

In this example, you will learn php replace string with another string example. I would like to show you replace string with another string in php - string. you can understand a concept of php replace string with another string with code examples. I’m going to show you about how to use function replace string with another string ?.

In this example replace string with another string in PHP. in this example, we will use to str_replace() function to replace string with another string. so Let's see following example with output.

Example : Replace String with Another String


index.php

<?php

// Create string

$str = "Welcome to Nicesnippets.com";

// Create string

$newStr = "Hello Developers Welcome to Our Website";

// Replace String with Another String

$result = str_replace( $str,$newStr, $str);

echo $result;

?>

Output:

Hello Developers Welcome to Our Website

I hope it could help you...

#PHP