Check if a String Contains a Substring in PHP
$myString = 'Hello Bob how are you?';
if (strpos($myString, 'Bob') !== false) {
echo "My string contains Bob";
}
4.25
4
phpCopy<?php
$mystring = "This is a PHP program.";
if (strpos($mystring, "PHP", 13) !== false) {
echo("True");
} else {
echo("False");
}
?>
Thank you!
4
0
4.43
7
phpCopy<?php
$mystring = "This is a PHP program.";
if (strpos($mystring, "program.") !== false) {
echo("True");
}
?>
Thank you!
7
0
3.75
8
$a = 'How are you?';
if (strpos($a, 'are') !== false) {
echo 'true';
}
Thank you!
8
0
4
6
phpCopy<?php
$mystring = "This is a php program.";
$search = "a";
if(preg_match("/{$search}/i", $mystring)) {
echo "True"; } else {
echo("False");
}
?>
Thank you!
6
0
Are there any code examples left?
New code examples in category PHP