Answers for "php is substring in string"

PHP
93

php string contains substring

$myString = 'Hello Bob how are you?';
if (strpos($myString, 'Bob') !== false) {
    echo "My string contains Bob";
}
Posted by: Guest on August-06-2019
6

php find if substring is in string

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

if ($result != false)
{
  // text found
}
Posted by: Guest on March-13-2020
0

Check if a String Contains a Substring in PHP

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

if (strpos($mystring, "program.") !== false) {
    echo("True");
}
?>
Posted by: Guest on April-23-2021
0

Check if a String Contains a Substring in PHP

phpCopy<?php
$mystring = "This is a php program.";
$search = "a";
if(preg_match("/{$search}/i", $mystring)) {
    echo "True"; } else {
    echo("False");
}
?>
Posted by: Guest on April-23-2021

Code answers related to "php is substring in string"

Browse Popular Code Answers by Language