仅从php中的url获取文件名,url中不存在任何变量值 [英] Get only filename from url in php without any variable values which exist in the url

查看:20
本文介绍了仅从php中的url获取文件名,url中不存在任何变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 php 中的 URL 获取没有任何 $_GET 变量值的文件名?

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

我的网址是 http://learner.com/learningphp.php?lid=1348

我只想从 URL 中检索 learningphp.php?

I only want to retrieve the learningphp.php from the URL?

如何做到这一点?

我使用了 basename() 函数,但它也提供了所有变量值:learntolearn.php?lid=1348,它们在 URL 中.

I used basename() function but it gives all the variable values also: learntolearn.php?lid=1348 which are in the URL.

推荐答案

这应该有效:

echo basename($_SERVER['REQUEST_URI'], '?' . $_SERVER['QUERY_STRING']);

但要注意 URL 中的任何恶意部分.

But beware of any malicious parts in your URL.

这篇关于仅从php中的url获取文件名,url中不存在任何变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆