SoFunction
Updated on 2025-04-04

Get URL filename suffix


<?php
$url = "/abc/de/?id=1";

//This is written by myself
function getUrl($url) {
    $date = explode('?', $url);
    $date = basename($date[0]);
    $date = explode('.', $date);
    return $date[1];
}

var_dump(getUrl($url));

//The following two are made online
function getExt($url){
   $arr = parse_url($url);

   $file = basename($arr['path']);
   $ext = explode(".",$file);
   return $ext[1];
}

var_dump(getExt($url));

 

function getName($url) {

   $w_param = pathinfo($url);

   $str = $w_param['extension'];

   list($type, $vars) = explode('?',$str);

   return $type;

}
echo 'start3'.date("Y-m-d H:i:s");
?>