“PHP contiene subcadena” Código de respuesta

Php verifique si la cadena contiene Word

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

la cadena PHP contiene

$string = 'The lazy fox jumped over the fence';

if (str_contains($string, 'lazy')) {
    echo "The string 'lazy' was found in the string\n";
}

TomatenTim

¿Cómo verifico si una cadena contiene una palabra específica PHP?

$a = 'How are you?';

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

Compruebe si la cadena contiene PHP de caracteres

// 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

La cadena PHP contiene cadena

$str = 'Hello World!';

if (strpos($str, 'World') !== false) {
    echo 'true';
}
Snippets

PHP contiene subcadena


<?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

Respuestas similares a “PHP contiene subcadena”

Preguntas similares a “PHP contiene subcadena”

Más respuestas relacionadas con “PHP contiene subcadena” en PHP

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código