“PHP contém substring” Respostas de código

PHP Verifique se a string contém palavras

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

String php contém

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

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

TomatenTim

Como faço para verificar se uma string contém uma palavra específica php

$a = 'How are you?';

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

Verifique se a string contém 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

string php contém string

$str = 'Hello World!';

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

PHP contém 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

Respostas semelhantes a “PHP contém substring”

Perguntas semelhantes a “PHP contém substring”

Mais respostas relacionadas para “PHP contém substring” em PHP

Procure respostas de código populares por idioma

Procurar outros idiomas de código