PHP String Replace Last 3 Characters Example

03-Apr-2023

.

Admin

PHP String Replace Last 3 Characters Example

Hi Dev,

This tutorial will give you example of php string replace last three characters example. This article will give you simple example of replace last three characters from string in php. I’m going to show you about php replace last three characters with code examples. I explained simply about how to use function replace last three characters?.

In this example string Replace Last Three Characters in PHP. in this example, we will use to substr() function to replace Last Three Characters. so Let's see following example with output.

Example : String Replace Last 3 Characters


index.php

<?php

// Create string

$str = "Welcome to Nicesnippets.org";

// Replace Last Three Characters

$newStr = substr($str, 0, -3).'com';

echo $newStr;

?>

Output:

Welcome to Nicesnippets.com

I hope it could help you...

#PHP