How to String Replace First Letter in PHP?

Nov 23, 2022

.

Admin

How to String Replace First Letter in PHP?

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...

#PHP