|
użytkowników online: 65
|
OPINIE UŻYTKOWNIKÓW
|
Porady zamieszczone tutaj przez Darka są pomocne w wielu chwilach. Wielokrotnie tworząc jakiś złożony serwis korzystam z tych porad. Można by tworzyć samemu te skrypty, ale tak naprawdę czy nie lepiej jest wziąć skrypt z tej strony i zmodyfikowac go dla swoich potrzeb? Wprawdzie możemy taki skrypt napisać sami, ale po co, skoro stracimy czas na coś, co ktoś juz napisał, przetestował i może zagwarantować, że działa poprawnie. Któryś raz z rzędu opłacam abonament i nie raz jeszcze opłacę. Kawał dobrej roboty i ogrom wiedzy w jednym miejscu.
Piotr Karamański Design Studio
|
|
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net
[Spis]
[A]
[B]
[C]
[D]
[E]
[F]
[G]
[H]
[I]
[J]
[K]
[L]
[M]
[N]
[O]
[P]
[Q]
[R]
[S]
[T]
[U]
[V]
[X]
[W]
[Z]
dirname (PHP 3, PHP 4, PHP 5) dirname -- Zwraca nazwę katalogu, będącego składową ścieżki Opisstring dirname ( string ścieżka )
Z podanego łańcucha zawierającego ścieżkę do pliku, funkcja ta
zwróci nazwę katalogu.
W Windows jako separator katalogu używany jest znak slash
(/) i backslash (\). W
innych środowiskach jest to slash (/).
Przykład 1. dirname() przykład |
<?php
$path = "/etc/passwd";
$file = dirname($path); ?>
|
|
Notatka:
W PHP 4.0.3, dirname() została poprawiona aby być
zgodną z POSIX. To znaczy, że jeśli w parametrze ścieżka
nie ma slasha, to zostanie zwrócona kropka ('.'), oznaczająca
bieżący katalog. W przeciwnym wypadku, zostanie zwrócony łańcuch podany w
parametrze path z usuniętymi /komponentami.
Zauważ, że to oznacza uzyskiwanie slasha lub kropki z
dirname() w sytuacjach w których starsza funkcjonalność
mogła dać Tobie pusty łańcuch.
Zachowanie dirname() zostało zmienione w PHP 4.3.0.
Sprawdź następujące przykłady:
dirname() jest binarnie bezpieczna od PHP 5.0.0
Patrz także: basename(),
pathinfo()
i realpath().
User Contributed Notesssl at bokehman dot com
21-Sep-2005 10:55
The way this function plays with slashes in windows is a pain so if you are trying to get the current directory I would use the following instead:
str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF'])
renich at woralelandia dot com
10-Aug-2005 07:15
--- Edited by tularis@php.net ---
You could also have a look at the getcwd() function
--- End Edit ---
A nice "current directory" function.
function current_dir()
{
$path = dirname($_SERVER[PHP_SELF]);
$position = strrpos($path,'/') + 1;
print substr($path,$position);
}
current_dir();
I find this usefull for a lot of stuff! You can maintain a modular site with dir names as modules names. At least I would like PHP guys to add this to the function list!
If there is anything out there like it, please tell me.
klugg this-is-junk at tlen dot pl
18-Jul-2005 04:14
Attention with this. Dirname likes to mess with the slashes.
On Windows, Apache:
<?php
echo '$_SERVER[PHP_SELF]: ' . $_SERVER['PHP_SELF'] . '<br />';
echo 'Dirname($_SERVER[PHP_SELF]: ' . dirname($_SERVER['PHP_SELF']) . '<br>';
?>
prints out
$_SERVER[PHP_SELF]: /index.php
Dirname($_SERVER[PHP_SELF]: \
tobylewis at mac dot com
24-Jun-2005 03:52
Since the paths in the examples given only have two parts (e.g. "/etc/passwd") it is not obvious whether dirname returns the single path element of the parent directory or whether it returns the whole path up to and including the parent directory. From experimentation it appears to be the latter.
e.g.
dirname('/usr/local/magic/bin');
returns '/usr/local/magic' and not just 'magic'
Also it is not immediately obvious that dirname effectively returns the parent directory of the last item of the path regardless of whether the last item is a directory or a file. (i.e. one might think that if the path given was a directory then dirname would return the entire original path since that is a directory name.)
Further the presense of a directory separator at the end of the path does not necessarily indicate that last item of the path is a directory, and so
dirname('/usr/local/magic/bin/'); #note final '/'
would return the same result as in my example above.
In short this seems to be more of a string manipulation function that strips off the last non-null file or directory element off of a path string.
Holger Th
|