Remove first 4 characters of a string with PHP

353,064

Solution 1

You could use the substr function to return a substring starting from the 5th character:

$str = "The quick brown fox jumps over the lazy dog."
$str2 = substr($str, 4); // "quick brown fox jumps over the lazy dog."

Solution 2

If you’re using a multi-byte character encoding and do not just want to remove the first four bytes like substr does, use the multi-byte counterpart mb_substr. This does of course will also work with single-byte strings.

Share:
353,064

Related videos on Youtube

Belgin Fish
Author by

Belgin Fish

Updated on March 11, 2021

Comments

  • Belgin Fish
    Belgin Fish over 3 years

    How can I remove the first 4 characters of a string using PHP?