How can PHP functions like substr() and strrpos() be used effectively in file manipulation tasks?

When working with file manipulation tasks in PHP, functions like substr() and strrpos() can be used effectively to extract specific parts of file paths or filenames. For example, substr() can be used to extract the file extension from a filename, while strrpos() can be used to find the position of the last occurrence of a specific character in a file path.

// Example: Extracting file extension using substr()
$filename = "example.txt";
$fileExtension = substr($filename, strrpos($filename, '.') + 1);
echo $fileExtension; // Output: txt