PHP Remove First and Last Character from String Example

Sep 22, 2022

.

Admin

PHP Remove First and Last Character from String Example

Hi Dev,

This post will give you example of php remove first and last character from string example. you will learn how to remove first and last character from string in php?. This tutorial will give you simple example of php remove first and last character from string. This post will give you simple example of string remove first and last character php example.

There are example to remove first and last character from strings in PHP. in this example, we will use to substr() function used to remove first and last character. so Let's see the following example with output.

Example: Remove First and Last Character


index.php

<?php

$str = "Welcome to Nicesnippets.comM";

//Remove First and Last Character of string

$result = substr($str, 1, -1);

echo $result;

?>

Output:

elcome to Nicesnippets.com

I hope it could help you...

#PHP