How to Remove First Character from String in PHP?

By Hardik Savani May 14, 2024 Category : PHP

Hey Guys,

This tutorial shows you php remove first character from string. you can understand a concept of how to remove first character from string in php. if you want to see an example of php remove first character from string example then you are in the right place. It's a simple example of remove first character from string php.

we will use substr() php function to remove first character from string. i will give you very simple examples to delete first character from string in php.

Example 1: PHP Remove First Character from String

index.php

<?php

/* Declare string variable */

$myString = "Welcome to ItSolutionStuff.com!";

/* Remove First Character of string */

$newString = substr($myString, 1);

/* Echo resulted string */

echo $newString;

?>

Output:

elcome to ItSolutionStuff.com!

Example 2: PHP Remove Last Character from String

index.php

<?php

/* Declare string variable */

$myString = "Welcome to ItSolutionStuff.com!";

/* Remove Last Character of string */

$newString = substr($myStr, 0, -1);

/* Echo resulted string */

echo $newString;

?>

Output:

Welcome to ItSolutionStuff.com

Example 3: PHP Remove First and Last Character from String

index.php

<?php

/* Declare string variable */

$myString = "Welcome to ItSolutionStuff.com!";

/* Remove First and Last Character of string */

$newString = substr($myStr, 1, -1);

/* Echo resulted string */

echo $newString;

?>

Output:

elcome to ItSolutionStuff.com

I hope it can help you...

Tags :
Shares