“Überprüfen Sie, ob die Zeichenfolge Zeichen -PHP enthält” Code-Antworten

PHP -Überprüfung, ob Zeichenfolge Word enthält

$myString = 'Hello Bob how are you?';
if (strpos($myString, 'Bob') !== false) {
    echo "My string contains Bob";
}
Grepper

Wie überprüfe ich, ob eine Zeichenfolge ein bestimmtes Wort PHP enthält

$a = 'How are you?';

if (strpos($a, 'are') !== false) {
    echo 'true';
}
Indian Gooner

So überprüfen Sie, ob eine Zeichenfolge ein Substring in PHP enthält

$a = 'How are you?';

if (strpos($a, 'are') !== false) {
    echo 'true';
}
Samson Munyira

Überprüfen Sie, ob die Zeichenfolge Zeichen -PHP enthält

// this method is new with PHP 8 and above
$haystack = "Damn, I wonder if this string contains a comma.";
if (str_contains($haystack, ",")) {
	echo "There is a comma!!";
}
Lonely Doge

PHP -Finden Sie, ob das Substring in String ist

$result = strpos("haystack", "needle");

if ($result != false)
{
  // text found
}
Meaxis

PHP enthält Substring


<?php
$mystring = 'abc';
$findme   = 'a';
$pos = strpos($mystring, $findme);

// Note our use of ===.  Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos === false) {
    echo "The string '$findme' was not found in the string '$mystring'";
} else {
    echo "The string '$findme' was found in the string '$mystring'";
    echo " and exists at position $pos";
}
?>

Kaotik

Ähnliche Antworten wie “Überprüfen Sie, ob die Zeichenfolge Zeichen -PHP enthält”

Fragen ähnlich wie “Überprüfen Sie, ob die Zeichenfolge Zeichen -PHP enthält”

Weitere verwandte Antworten zu “Überprüfen Sie, ob die Zeichenfolge Zeichen -PHP enthält” auf PHP

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen