How can the pathinfo() function be used to manipulate strings in PHP?

The pathinfo() function in PHP can be used to extract information about a file path, such as the directory name, base name, extension, etc. This function can be particularly useful for manipulating strings related to file paths, like extracting the file extension or filename. By using pathinfo(), you can easily parse and extract specific parts of a file path string.

$file_path = '/path/to/file/example.txt';
$path_info = pathinfo($file_path);

$file_extension = $path_info['extension'];
$file_name = $path_info['filename'];

echo "File extension: " . $file_extension . "\n";
echo "File name: " . $file_name;