Örneğin, nasıl Output.map
from
F:\Program Files\SSH Communications Security\SSH Secure Shell\Output.map
PHP ile?
Sen basename arıyoruz.
PHP manuel örnek:
<?php
$path = "/home/httpd/html/index.php";
$file = basename($path); // $file is set to "index.php"
$file = basename($path, ".php"); // $file is set to "index"
?>
Ben fonksiyonunu PATHINFO
wich kullanmak için yolun parçaları ile bir dizi oluşturur kullanarak yaptık! Örneğin bunu yapabilirsiniz:
<?php
$xmlFile = pathinfo('/usr/admin/config/test.xml');
function filePathParts($arg1) {
echo $arg1['dirname'], "\n";
echo $arg1['basename'], "\n";
echo $arg1['extension'], "\n";
echo $arg1['filename'], "\n";
}
filePathParts($xmlFile);
?>
Bu dönecektir:
/usr/admin/config
test.xml
xml
test
The use of this function is available since PHP 5.2.0! Then you can manipulate all the parts as you need. For example to use the full path you can do this:
$fullPath = $xmlFile['dirname'].'/'.$xmlSchema['basename'];
Ben de bu yöntemi kullanabilirsiniz, bu cevabı çok yararlı olmuştur diliyorum. Iyi günler ;)
basename
a> fonksiyonu ne istediğinizi vermelidir:
Given a string containing a path to a file, this function will return the base name of the file.
Örneğin, kılavuzun sayfasını alıntı:
<?php
$path = "/home/httpd/html/index.php";
$file = basename($path); // $file is set to "index.php"
$file = basename($path, ".php"); // $file is set to "index"
?>
Ya da senin durumunda:
$full = 'F:\Program Files\SSH Communications Security\SSH Secure Shell\Output.map';
var_dump(basename($full));
Alırsınız:
string(10) "Output.map"
Kullanmak basename() function olabilir
Basename benim için çalışmıyor. Ben bir formu (dosyası) dosya var. Google chrome (mac os x lion) üzerine dosya değişken olur:
c:\fakepath\file.txt
Ben kullandığınızda:
basename($_GET['file'])
döndürür:
c:\fakepath\file.txt
Yani bu durumda güneş Junwen cevap iyi çalışır.
Firefox dosyanın değişken bu fakepath içermez.
aldım ama aynı zamanda (bir değil burada) başka bir tane bulmak, bu yüzden
ilanıyla bir cevap geldi
Şimdi ile SplFileInfo
SplFileInfo The SplFileInfo class offers a high-level object oriented interface to information for an individual file.
Ref, http://php.net/manual/en/splfileinfo.getfilename.php
$info = new SplFileInfo('/path/to/foo.txt');
var_dump($info->getFilename());
o / p: string (7) "foo.txt"