Join my Laravel for REST API's course on Udemy 👀

Remove the first character from a string in PHP

May 4, 2022  ‐ 1 min read

To remove the first character from a string in PHP your easiest best is probably the substr() function, short for substring.

As a first argument the substr() takes a string, as its second argument the offset for your substring. To remove just the first character of the string you want to use an offset of 1, string indexes start at 0. So to have your string start from the second character you need to use an offset of 1.

Take a look at the following example which removes the @ character from a string.

<?php

$account = "@koen";
$username = substr($account, 1);

echo $username;
// => "koen"