Funkce PHP strchr().
Příklad
Najděte první výskyt "world" uvnitř "Hello world!" a vrátit zbytek řetězce:
<?php
echo strchr("Hello world!","world");
?>
Definice a použití
Funkce strchr() hledá první výskyt řetězce uvnitř jiného řetězce.
Tato funkce je aliasem funkce strstr() .
Poznámka: Tato funkce je binárně bezpečná.
Poznámka: Tato funkce rozlišuje malá a velká písmena. Pro vyhledávání bez ohledu na velikost písmen použijte funkci stristr() .
Syntax
strchr(string,search,before_search);
Hodnoty parametrů
Parameter | Description |
---|---|
string | Required. Specifies the string to search |
search | Required. Specifies the string to search for. If this parameter is a number, it will search for the character matching the ASCII value of the number |
before_search | Optional. A boolean value whose default is "false". If set to "true", it returns the part of the string before the first occurrence of the search parameter. |
Technické údaje
Návratová hodnota: | Vrátí zbytek řetězce (od odpovídajícího bodu) nebo FALSE, pokud řetězec, který chcete hledat, nebyl nalezen. |
---|---|
Verze PHP: | 4+ |
Seznam změn: | Parametr before_search byl přidán v PHP 5.3 |
Další příklady
Příklad
Vyhledejte v řetězci hodnotu ASCII „o“ a vraťte zbytek řetězce:
<?php
echo strchr("Hello world!",111);
?>
Příklad
Vraťte část řetězce před první výskyt "world":
<?php
echo strchr("Hello world!","world",true);
?>