252

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

Spotlight
  • 472
  • 1
  • 11
  • 22
Belgin Fish
  • 19,187
  • 41
  • 102
  • 131

2 Answers2

504

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."
Daniel Vandersluis
  • 91,582
  • 23
  • 169
  • 153
28

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.

Gumbo
  • 643,351
  • 109
  • 780
  • 844