我有一个像这样的网址字符串:
http://example.com/sfm?dir=uploads/sfm/root/folder5/file.zip
echo $_GET['extract']
输出:uploads/sfm/root/folder5/file.zip
我怎样才能删除最后一个file.zip以便
echo $_GET['extract']
输出:uploads/sfm/root/folder5/
答案 0 :(得分:3)
使用以下代码:
$String = $_GET['extract'];
$Words = explode('/', $String);
echo end($Words );
答案 1 :(得分:1)
只需使用dirname - 返回父目录的路径
echo dirname($_GET['extract'])."/";
答案 2 :(得分:1)
尝试:
$url = "uploads/sfm/root/folder5/file.zip";
$urlArr= explode("/",$url);
array_pop($urlArr);
echo implode("/",$urlArr);
答案 3 :(得分:0)
也许这有效:
echo substr((string)$_GET['extract'],26);
答案 4 :(得分:0)
试试这个
<?php
$ss ="uploads/sfm/root/folder5/file.zip";
$vv = explode('/',$ss);
array_pop($vv);
$mm =implode('/',$vv);
print_r($mm);
?>