Описание
string stristr
( string $haystack
, string $needle
)
Возвращает подстроку строки haystack начиная с первого вхождения needle до конца строки. Эта функция не учитывает регистр сиволов.
Если подстрока needle не найдена, stristr() возвращает FALSE.
Если needle не является строкой, он приводится к целому и трактуется как код символа.
Пример #1 Пример использования stristr()
<?php
$email = 'USER@EXAMPLE.com';
$domain = stristr($email, 'e');
echo $domain;
// выводит ER@EXAMPLE.com
?>
Замечание: Эта функция безопасна для обработки данных в двоичной форме.
См. также описание функций strstr(), strrchr(), substr() и ereg().
- addcslashes
- addslashes
- bin2hex
- chop
- chr
- chunk_split
- convert_cyr_string
- convert_uudecode
- convert_uuencode
- count_chars
- crc32
- crypt
- echo
- explode
- fprintf
- get_html_translation_table
- hebrev
- hebrevc
- hex2bin
- html_entity_decode
- htmlentities
- htmlspecialchars_decode
- htmlspecialchars
- implode
- join
- lcfirst
- levenshtein
- localeconv
- ltrim
- md5_file
- md5
- metaphone
- money_format
- nl_langinfo
- nl2br
- number_format
- ord
- parse_str
- printf
- quoted_printable_decode
- quoted_printable_encode
- quotemeta
- rtrim
- setlocale
- sha1_file
- sha1
- similar_text
- soundex
- sprintf
- sscanf
- str_getcsv
- str_ireplace
- str_pad
- str_repeat
- str_replace
- str_rot13
- str_shuffle
- str_split
- str_word_count
- strcasecmp
- strchr
- strcmp
- strcoll
- strcspn
- strip_tags
- stripcslashes
- stripos
- stripslashes
- stristr
- strlen
- strnatcasecmp
- strnatcmp
- strncasecmp
- strncmp
- strpbrk
- strpos
- strrchr
- strrev
- strripos
- strrpos
- strspn
- strstr
- strtok
- strtolower
- strtoupper
- strtr
- substr_compare
- substr_count
- substr_replace
- substr
- trim
- ucfirst
- ucwords
- vfprintf
- vprintf
- vsprintf
- wordwrap
Коментарии
There was a change in PHP 4.2.3 that can cause a warning message
to be generated when using stristr(), even though no message was
generated in older versions of PHP.
The following will generate a warning message in 4.0.6 and 4.2.3:
stristr("haystack", "");
OR
$needle = ""; stristr("haystack", $needle);
This will _not_ generate an "Empty Delimiter" warning message in
4.0.6, but _will_ in 4.2.3:
unset($needle); stristr("haystack", $needle);
Here's a URL that documents what was changed:
http://groups.google.ca/groups?selm=cvshholzgra1031224321%40cvsserver
An example for the stristr() function:
<?php
$a = "I like php";
if (stristr("$a", "LikE PhP")) {
print ("According to \$a, you like PHP.");
}
?>
It will look in $a for "like php" (NOT case sensetive. though, strstr() is case-sensetive).
For the ones of you who uses linux.. It is similiar to the "grep" command.
Actually.. "grep -i".
<?php
function stristr_reverse($haystack, $needle) {
$pos = stripos($haystack, $needle) + strlen($needle);
return substr($haystack, 0, $pos);
}
$email = 'USER@EXAMPLE.com';
echo stristr_reverse($email, 'er');
// outputs USER
?>
Just been caught out by stristr trying to converting the needle from an Int to an ASCII value.
Got round this by casting the value to a string.
<?php
if( !stristr( $file, (string) $myCustomer->getCustomerID() ) ) {
// Permission denied
}
?>
I think there is a bug in php 5.3 in stristr with uppercase Ä containing other character
http://pastebin.com/5bP6uztY
if you search only with täry it works, but as soon as the word is tärylä it does not. TÄRYL works fine