1$myString = 'Hello Bob how are you?';
2if (strpos($myString, 'Bob') !== false) {
3 echo "My string contains Bob";
4}
1$a = 'How are you?';
2
3if (strpos($a, 'are') !== false) {
4 echo 'true';
5}
1phpCopy<?php
2$mystring = "This is a PHP program.";
3
4if (strpos($mystring, "program.") !== false) {
5 echo("True");
6}
7?>
8
1phpCopy<?php
2$mystring = "This is a php program.";
3$search = "a";
4if(preg_match("/{$search}/i", $mystring)) {
5 echo "True"; } else {
6 echo("False");
7}
8?>
9
1phpCopy<?php
2$mystring = "This is a PHP program.";
3
4if (strpos($mystring, "PHP", 13) !== false) {
5 echo("True");
6} else {
7 echo("False");
8}
9?>
10