What are the potential pitfalls of using substr() and strtolower() functions in PHP when working with file extensions?

When working with file extensions in PHP, using substr() and strtolower() functions can introduce potential pitfalls such as incorrect file extension extraction or case sensitivity issues. To avoid these problems, it is recommended to use pathinfo() function which provides a more reliable way to extract file extensions and handle them in a case-insensitive manner.

// Using pathinfo() function to extract file extension in a case-insensitive manner
$file = "example.TXT";
$extension = pathinfo($file, PATHINFO_EXTENSION);
echo $extension; // Outputs: txt