What are the potential pitfalls of using substr in PHP when removing characters from a string?

Using substr in PHP to remove characters from a string can lead to issues if the start or length parameters are not carefully calculated. If the start position is negative, it will count from the end of the string. If the length parameter is negative, it will be interpreted as counting from the end of the string as well. To avoid these pitfalls, it's important to properly calculate the start and length parameters before using substr.

// Example of safely removing characters from a string using substr
$string = "Hello, World!";
$start = 0; // Starting position
$length = 5; // Number of characters to remove
$newString = substr($string, 0, $start) . substr($string, $start + $length);
echo $newString; // Output: " World!"