PHP String Replace First Number Example
Hi Dev,
In this example, you will learn php string replace first number example. I would like to show you replace first number in php - string. you can understand a concept of php replace first number with code examples. I’m going to show you about how to use function replace first number ?.
In this example string replace first number in PHP. in this example, we will use to preg_replace() function to replace first Number. so Let's see following example with output.
Example : String Replace First Number
index.php
<?php
// create string
$str ="Hell2 2Nicesnippets.com";
// Replace First Number
$newStr = preg_replace('/2/', 'o', $str, 1);
echo $newStr;
?>
Output:
Hello 2Nicesnippets.com
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