PHP 删除 url 中的 query string

function removeQueryStringFromUrl($url) {
    if (substr($url,0,4) =="http") {
    $urlPartsArray = parse_url($url);
    $outputUrl = $urlPartsArray['scheme']. '://'. $urlPartsArray['host']. ( isset($urlPartsArray['path'])? $urlPartsArray['path'] : '' );
    } 
else { $URLexploded = explode("?", $url, 2); $outputUrl = $URLexploded[0]; } return $outputUrl; }

 

测试链接:

https://ideone.com/PvpZ4J

posted @ 2019-02-20 01:13  Ryan_zheng  阅读(507)  评论(0编辑  收藏  举报