How can I remove three characters at the end of a string in PHP?

How can I remove three characters at the end of a string in PHP?

"abcabcabc" would become "abcabc"!


Solution 1:

Just do:

echo substr($string, 0, -3);

You don't need to use a strlen call, since, as noted in the substr documentation:

If length is given and is negative, then that many characters will be omitted from the end of string

Solution 2:

<?php echo substr("abcabcabc", 0, -3); ?>