NOVINKA: Najžiadanejšie rekvalifikačné kurzy teraz s 50% zľavou + kurz AI ZADARMO. Nečakaj, táto ponuka dlho nevydrží! Zisti viac:

PHP - mb_strpos

Trieda

Koreň \ Bez triedy

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ázovDátový typPredvolená hodnotaPopis
$haystackstring

The string (so-called haystack).

$needlestring

The substring to find (so-called needle).

$offsetint 0

The offset which specifies how many characters will be skipped from the start of the string.

$encodingstring 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

      Aktivity