Press "Enter" to skip to content

【PHP 面试题】从 url 获取文件的扩展名

function getExt1 () {
    $url_path = "http://www.sina.com.cn/abc/de/fg.php?id=1";
    $temp = pathinfo($url_path, PATHINFO_EXTENSION);  //    php?id=1
    $temp = explode("?", $temp);
    echo $temp[0];  // php
}
function getExt2 () {
    $url_path = "http://www.sina.com.cn/abc/de/fg.php?id=1";
    // ["scheme" => "http","host" => "新浪首页","path" => "/abc/de/fg.php","query" => "id=1"]
    $temp = parse_url($url_path);
    echo pathinfo($temp['path'], PATHINFO_EXTENSION);
}

 

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注