How can the str_replace function be used to remove specific parts of a file path in PHP?

To remove specific parts of a file path in PHP using the str_replace function, you can simply replace the unwanted parts with an empty string. This can be useful when you need to manipulate file paths, such as removing a specific directory or file extension.

$file_path = "/path/to/file/example.txt";
$unwanted_part = "/path/to/";

$cleaned_path = str_replace($unwanted_part, '', $file_path);

echo $cleaned_path; // Output: "file/example.txt"