What are the best practices for using preg_replace to filter parts of a filename in PHP?
When using preg_replace to filter parts of a filename in PHP, it's important to use proper regular expressions to target the specific parts you want to filter out. This can help prevent unintended modifications to the filename. Additionally, it's recommended to use the 'i' modifier in the regular expression to make the pattern case-insensitive.
$filename = "example_file.jpg";
$filtered_filename = preg_replace('/\.(jpg|png|gif)$/i', '', $filename);
echo $filtered_filename; // Output: example_file