How to Get filename from a variable (url) in php?

前端 未结 4 853
孤城傲影
孤城傲影 2021-01-16 08:47

That is not about getting file name from the url of current page. I have a php file like that.



        
4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-16 09:24

    You can also use string functions like strrpos to get the last position of '/' and then use the substr and strlen functions to get the last part of the string.

    $fileurl = 'http://example.com/filepath/filepath2/myfile.doc'; $file_name=substr($fileurl,strrpos($fileurl,'/')+1,strlen($fileurl));

    echo $file_name;
    

提交回复
热议问题