php - 尝试截断 URI/URL 的文件部分

标签 php string url

我正在尝试剪切 URI 的最后部分,如下所示:

public://path1/path2/path3/filename.extension

最终我只想要 public://path1/path2/path3/public://path1/path2/path3

我尝试过使用explode,但是URL的://部分似乎有一些问题。我想看看是否有办法用 substr 和 strpos 来做到这一点。

有什么想法吗?

哦,我没说清楚,我的意思是 PHP。

最佳答案

我的建议:

$url = 'http://public/protected/private/filename.php';
$url = str_replace(strrchr($url, '/'), '', $url);
echo $url; // Displays: http://public/protected/private

文档:

关于php - 尝试截断 URI/URL 的文件部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23916794/

相关文章:

PHP - 动态页面 - 为每个动态页面使用单独的 CSS 文件

php - 变量后直接回显文本

java - 比较两个长字符串

r - R : Function returns both error and warning - store both with tryCatch()

url - GUID 与 int : Does it makes any difference for SEO?

url - 为什么http ://contain two slashes and file:///three in a browser navigation bar?

php 如果迭代器可被动态列的语句整除

php - XDebug,如何避免每次都停在index.php?

java - 在文件中搜索字符串并返回下一行(在 Java 中)

string - 如何从 Bash 中的路径字符串中删除文件后缀和路径部分?