PHP Remove First 2, 3, 4, 5, 10, etc Character From String Example

Sep 20, 2022

.

Admin

PHP Remove First 2, 3, 4, 5, 10, etc Character From String Example

Hi Dev,

This tutorial shows you how to remove first 2, 3, 4, 5, 10, etc character from string in php?. you can understand a concept of remove first 2, 3, etc character from string in php example. Here you will learn remove first from string php.

There ara three ways to remove first 2, 3, 4, 5, etc Character From string in php. in the first example, we will use to substr() function and the second example is use to ltrim() function this exampale.so Let's see the following example with output.

Example 1: PHP Remove First 2 Character


index.php

<?php

$str = "Hi Nicesnippets.com";

// Remove First 2, 3, 4, etc Character From string

$result = substr($str, 2);

echo $result;

?>

Output:

Nicesnippets.com

Example 2: PHP Remove First 4 Character

index.php

<?php

$str = "Hello World!";

// Remove First 2, 3, 4, etc Character From string

$result = ltrim($str, "Hell");

echo $result;

?>

Output:

o World!

I hope it could help you...

#PHP