Tutorialsplane

Php remove first character from string


Php remove first character from string : Sometimes in few cases we need to remove first character from string in php. There are many ways to remove first character from string. Here in this tutorial we are going to explain the simplest method with example and demo.


Php remove first character from string Syntax & Example

You can use substr() function to remove the first character from string as below –

Php remove first character from string : Remove First Letter Using substr

<?php $string = "Hello World!";
echo substr($string, 1);
??>

Try it »

If you run the above example it will produce the output something like this –


More Example :

Let us have some more examples –


Remove first character from string : Using ltrim

If you know the first character, you can remove the string as below using the ltrim function-

Php remove first character from string : Using substr

<?php $string = "Hello World!";
echo ltrim($string, 'H');
??>

Try it »

Remove first character from string : Using Regular Expression

You can remove first letter using the regular expression also as below –

Php remove first character from string : Using Regular Expression Example

<?php $string = "AWelcome";
echo preg_replace('/^./', '', $string);
??>

Try it »

If you run the above example it will produce the output something like this –

Php - FAQ