$str = "d:/information/23/45/readme.txt";
$Array = explode($str);$temp = $Array[count($Array)-1];$temp 即为最后取值!

解决方案 »

  1.   

    $string = array_pop(explode("/",$str));
      

  2.   

    $str="d:/information/23/45/readme.txt";
    $arrpath=pathinfo($str);
    print_r($arrpath["basename"]);用这个吧
      

  3.   

    这个不知行不行.$str = "d:/information/23/45/readme.txt";$arr = @explode("/",$str);$end = array_pop($arr);echo $end;
      

  4.   

    各位大哥的意见都很好,可是小弟遇到另外一个麻烦,应该是说小弟表述得不太清楚。
      我是想搞一个文件浏览器,最近需要根据权限来分配根目录来访问,原来只有一个根目录的情况下,只有能访问的文件就能下载,但是现在用登陆条件来改变了根目录后,发现只有跟根目录是同一个目录下的文件才能被正确下载,子目录的文件下载会出现问题,我把源文件贴上来,大家看看是怎么一回事?
      <?php
    /*This script sends to the client
    the content of a server file filename*/
    require("path.ini");
    session_start();
    set_time_limit(600);
    $crlf="\n";/* get the variable $dir*/
    $filename=$_GET["filename"];/*check path security*/
    require("lib/inc/security.inc");/*if(!file_exists("$currentpath/$filename")) {
    Header("Location: unreadf.php?filename="."$currentpath/$filename");
    exit;
    }*//*check access mode*/
    require("explorer.cfg");$allowbrowse= $AllowSelfBrowse || !strstr($filename,basename(dirname($GLOBALS["SCRIPT_FILENAME"]))); if(!$allowbrowse) {
      print "sending a file from the explorer itself is forbidden (see your administrator)\n";
      exit();
      }
    // $a=basename($filename);
    $str=$filename;
    $arrpath=pathinfo($str);
    print_r($arrpath["basename"]);
    header("Content-disposition: filename=".str_replace("/",'',$arrpath["basename"]));header("Content-type: application/octet-stream");
    header("Pragma: no-cache");
    header("Expires: 0");if ($_SESSION['nas1send']==true)
    {
    readfile($currentpath.'/nas1'.$filename);
    }
     echo $currentpath.'/nas1'.$filename;if ($_SESSION['nas2send']==true)
    {
    readfile($currentpath.'/nas2'.$filename);
    }
    if ($_SESSION['nas3send']==true)
    {
    readfile($currentpath.'/nas3'.$filename);
    }
    //echo "$crlf";//exit();
    ?>
      

  5.   

    <?php
    $str ="d:/information/23/45/readme.txt";
    echo basename($str);
    ?>