What potential issues can arise when using the substr() function in PHP?

One potential issue that can arise when using the substr() function in PHP is that it may return unexpected results if the start parameter is negative. To solve this issue, you can calculate the correct start position by adding the length of the string to the negative start parameter.

$string = "Hello, World!";
$start = -6;
$length = 5;

if ($start < 0) {
    $start = strlen($string) + $start;
}

$substring = substr($string, $start, $length);
echo $substring; // Outputs "World"