Remove first 4 characters of a string with PHP

PhpStringCharacter

Php Problem Overview


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

Php Solutions


Solution 1 - Php

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 - Php

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBelgin FishView Question on Stackoverflow
Solution 1 - PhpDaniel VandersluisView Answer on Stackoverflow
Solution 2 - PhpGumboView Answer on Stackoverflow