What are the potential pitfalls of using substr() to extract specific parts of a string in PHP?

Using substr() to extract specific parts of a string in PHP can lead to errors if the start or length parameters are not carefully calculated. If these parameters are incorrect, it can result in extracting the wrong portion of the string or even causing runtime errors. To avoid these pitfalls, it's important to double-check the start and length values before using substr().

// Example of using substr() with proper start and length values
$string = "Hello, World!";
$start = 7; // Start position of the substring
$length = 5; // Length of the substring
$substring = substr($string, $start, $length);
echo $substring; // Outputs "World"