확장자 이후 자르기
<?php
function removeQueryAfterExtension($url) {
// Regular expression to match a common image extension and remove everything after it
$pattern = '/(\.jpg|\.jpeg|\.png|\.gif|\.bmp|\.webp)(\?.*)?$/i';
// Replace the matched pattern, removing the query part
$cleanedUrl = preg_replace($pattern, '$1', $url);
return $cleanedUrl;
}
// Example URL
$url = "https://example.com/image.jpg?q=70&fit=crop&w=1100&h=618&dpr=1";
// Clean the URL
$cleanedUrl = removeQueryAfterExtension($url);
// Output the cleaned URL
echo $cleanedUrl; // Outputs: https://example.com/image.jpg
?>