What potential pitfalls should be avoided when using the substr function in PHP?

When using the substr function in PHP, it's important to avoid pitfalls such as providing a negative length parameter, which can lead to unexpected results. To avoid this, always ensure that the length parameter is a positive integer when using substr. Additionally, be cautious when using substr with multibyte characters, as it may not work as expected due to the way multibyte characters are encoded.

// Avoid using a negative length parameter with substr
$substring = substr($string, $start, abs($length));