How to String Replace First Letter in PHP?
Nov 23, 2022
Hi Dev,
In this article, we will learn how to replace the first letter is a string in php.this is a common problem for php developers.you may need to change or replace the first letter of a string.following the code example shows how to change the first letter of a string in php
There are example to check if string replace first letter in php. in this example, we will use to substr_replace() function to check if how to string replace first letter in php. so let's the following example with output.
Example 1:
index.php
<?php
// string replace first letter
$string = "Hello Developers";
echo "Given string: " . $string . "\n";
echo "Updated string: " . substr_replace($string, "Hi", 0, 5) . "\n";
?>
Output:
Given string: Hello Developers
Updated string: Hi Developers
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