Get only filename from url in php without any variable values which exist in the url

前端 未结 12 696
北荒
北荒 2020-12-05 12:41

I want to get filename without any $_GET variable values from a URL in php?

My URL is http://learner.com/learningphp.php?lid=1348

I

12条回答
  •  自闭症患者
    2020-12-05 13:18

    Try the following code:

    For PHP 5.4.0 and above:

    $filename = basename(parse_url('http://learner.com/learningphp.php?lid=1348')['path']);
    

    For PHP Version < 5.4.0

    $parsed = parse_url('http://learner.com/learningphp.php?lid=1348');
    $filename = basename($parsed['path']);
    

提交回复
热议问题