1$myString = 'Hello Bob how are you?';
2if (strpos($myString, 'Bob') !== false) {
3 echo "My string contains Bob";
4}
1$a = 'Hello world?';
2
3if (strpos($a, 'Hello') !== false) { //PAY ATTENTION TO !==, not !=
4 echo 'true';
5}
6if (stripos($a, 'HELLO') !== false) { //Case insensitive
7 echo 'true';
8}
1if (strpos($haystack,$needle) !== false) {
2 echo "$haystack contains $needle";
3}
1$myString = 'Hello Bob how are you?';
2if (strpos($myString, 'Bob') !== false) {
3 echo "My string contains Bob";
4}
1// returns true if $needle is a substring of $haystack
2function contains($haystack, $needle){
3 return strpos($haystack, $needle) !== false;
4}
1phpCopy<?php
2$mystring = "This is a PHP program.";
3
4if (strpos($mystring, "program.") !== false) {
5 echo("True");
6}
7?>
8