PHP - mb_strpos
Trieda
Metóda - mb_strpos
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
The mb_strpos() function finds the position of the first
occurrence of a substring in a string.
There is also a mb_strrpos() function (extra r as
reverse) what works exactly the same way as mb_strpos(), but it is
searching from the end of the string. This is useful, for example, for checking
the file extension.
Procedurálne
- function mb_strpos (string $haystack, string $needle, int $offset = 0, string $encoding = mb_internal_encoding()) : int
Parametre
| Názov | Dátový typ | Predvolená hodnota | Popis |
|---|---|---|---|
| $haystack | string | The string (so-called haystack). | |
| $needle | string | The substring to find (so-called needle). | |
| $offset | int | 0 | The offset which specifies how many characters will be skipped from the start of the string. |
| $encoding | string | mb_internal_encoding() | The encoding. |
Mávratovej hodnoty
Vracia: int
The function returns the position of the first occurrence of a substring what can be even 0 (when the substring starts at the first position in the text). If the function does not find the substring, it returns FALSE. To distinguish FALSE from 0, we have to compare it with === or !==.
Príklady
<?php
if (mb_strpos("This is a simple string", "string") !== false)
echo ("Found");
else
echo ("Not found");
Súvisiace manuály
- function mb_internal_encoding (string $encoding = mb_internal_encoding()) : mixed
