“Verifique se uma string contém uma substring no PHP” 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

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

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

Verifique se uma string contém uma substring no PHP

phpCopy<?php
$mystring = "This is a PHP program.";

if (strpos($mystring, "program.") !== false) {
    echo("True");
}
?>
CodeGuruDev

Verifique se uma string contém uma substring no PHP

phpCopy<?php
$mystring = "This is a php program.";
$search = "a";
if(preg_match("/{$search}/i", $mystring)) {
    echo "True"; } else {
    echo("False");
}
?>
CodeGuruDev

PHP Verifique se a string contém palavras

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

Respostas semelhantes a “Verifique se uma string contém uma substring no PHP”

Perguntas semelhantes a “Verifique se uma string contém uma substring no PHP”

Procure respostas de código populares por idioma

Procurar outros idiomas de código