|
użytkowników online: 16
|
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]
strrchr (PHP 3, PHP 4, PHP 5) strrchr --
Find the last occurrence of a character in a string
Descriptionstring strrchr ( string haystack, string needle )
This function returns the portion of
haystack which starts at the last
occurrence of needle and goes until the
end of haystack.
Returns FALSE if needle is not found.
If needle contains more than one
character, only the first is used in PHP 4. This behavior is different from that
of strchr().
If needle is not a string, it is converted
to an integer and applied as the ordinal value of a character.
Przykład 1. strrchr() example |
<?php
$dir = substr(strrchr($PATH, ":"), 1);
$text = "Line 1\nLine 2\nLine 3";
$last = substr(strrchr($text, 10), 1 );
?>
|
|
strrchr() has been binary safe since PHP 4.3.0
See also strstr(), substr(), and
stristr().
User Contributed Notesfreakinunreal at hotmail dot com
25-Dec-2005 07:54
to marcokonopacki at hotmail dot com.
I had to make a slight change in your function for it to return the complete needle inclusive.
// Reverse search of strrchr.
function strrrchr($haystack,$needle)
{
// Returns everything before $needle (inclusive).
//return substr($haystack,0,strpos($haystack,$needle)+1);
// becomes
return substr($haystack,0,strpos($haystack,$needle)+strlen($needle));
}
Note: the +1 becomes +strlen($needle)
Otherwise it only returns the first character in needle backwards.
arcesis - gmail - com
11-Nov-2005 03:26
A quick way to get file's extension (if it has one, otherwise you get an empty string), which can be used when you want to rename the file but keep the old extension. Or for similar purposes. Temporary variable is used just because it's slightly faster to store the value than to run the strrchr() function again.
<?php
$ext = substr(($t=strrchr("file.ext",'.'))!==false?$t:'',1);
?>
Primo Anderson Do S
|