PHP Replace String with Another String Example
Nov 25, 2022
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...
- How To Use Php Conditional Statement Example
- How to Check if String Contains Regex in PHP?
- PHP Array_column() Function Example
- PHP Generate List of Random Numbers Between 0 and 100 Example
- How to User Login with Facebook in PHP?
- How to Explode Every Character into Array Using PHP Example?
- PHP Form Validation Tutorial
- PHP Convert XML to JSON Example