Autor Zpráva
embebito52233
Profil *
Dobrý den,

chtěl bych se zeptat, jak mám zjistit, jestli v proměnné je daný text.
Mám třeba proměnnou $text a v něm text Jmeno: bla - > $text = "Jméno: bla";
Jak mám zjistit, jestli proměnná $text obsahuje slovo "Jméno"?
Googloval jsem, ale nemůžu nic najít.
Díky moc.
Jan Tvrdík
Profil
embebito52233:
strpos
embebito52233
Profil *
$najdi = "Jméno";
$y = StrPos($text,$najdi);
if($y == false)
{
    die("Chyba");
}
Nefunguje..
peta
Profil
http://www.php.net/function.strpos

Returns the position of where the needle exists relative to the beginning of the haystack string (independent of offset). Also note that string positions start at 0, and not 1.
Returns FALSE if the needle was not found.

Warning

This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.

Znamena to, ze funkce vraci pozici retezce, cislovane od nuly nebo false. Nula odpovida podmince ==false a ze mas pouzit ===.

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0