strlen() counts bytes. $s[0] reads one byte and $s[-1] the last (negative offsets since PHP 7.1; the old $s{0} was removed in 8.0). In substr($s, $start, $length), a negative start counts from the end, a negative length stops short of the end, and a start past the end returns '' (since 8.0, not false).
<?php
$sku = 'BK-2026-00042';
echo strlen($sku), ' ', $sku[0], $sku[-1], ' ', substr($sku, 3, 4), ' ', substr($sku, -5),
' ', substr($sku, 3, -6), " [", substr($sku, 99), "]\n";
echo str_pad('42', 6, '0', STR_PAD_LEFT), ' ', str_pad('Total', 9, '.'), '9.50 ',
str_repeat('=-', 3), ' ', strrev('stressed'), "\n";
$review = 'Great book. Great price. Would buy again!';
echo substr_count($review, 'Great'), ' ', str_word_count($review), ' ',
substr_replace($sku, '*****', -5), "\n";Output
13 B2 2026 00042 2026 [] 000042 Total....9.50 =-=-=- desserts 2 7 BK-2026-*****
Byte counting is right for codes, hashes and hex, and wrong for text people read: substr('café', 0, 4) returns "caf" plus half of é, and str_word_count('café crème') returns 3. Subsection 4.6.10 gives the character-aware versions.