What potential pitfalls should be considered when using the substr function in PHP for string manipulation?

When using the substr function in PHP for string manipulation, it's important to consider the potential pitfalls of off-by-one errors when specifying the start and length parameters. These errors can lead to unexpected results or even errors in your code. To avoid this, make sure to carefully calculate the correct start and length values based on the specific use case.

// Example of using substr function with correct start and length parameters
$string = "Hello, World!";
$start = 7; // Start at the 8th character
$length = 5; // Get 5 characters
$substring = substr($string, $start, $length);
echo $substring; // Output: World