1$myString = 'Hello Bob how are you?';
2if (strpos($myString, 'Bob') !== false) {
3 echo "My string contains Bob";
4}
1
2<?php
3$mystring = 'abc';
4$findme = 'a';
5$pos = strpos($mystring, $findme);
6
7// Note our use of ===. Simply == would not work as expected
8// because the position of 'a' was the 0th (first) character.
9if ($pos === false) {
10 echo "The string '$findme' was not found in the string '$mystring'";
11} else {
12 echo "The string '$findme' was found in the string '$mystring'";
13 echo " and exists at position $pos";
14}
15?>
16
17
1$result = strpos("haystack", "needle");
2
3if ($result != false)
4{
5 // text found
6}
1$mystring = 'abc';
2$findme = 'a';
3$pos = strpos($mystring, $findme);
4
5// Note our use of ===. Simply == would not work as expected
6// because the position of 'a' was the 0th (first) character.
7if ($pos === false) {
8 echo "The string '$findme' was not found in the string '$mystring'";
9} else {
10 echo "The string '$findme' was found in the string '$mystring'";
11 echo " and exists at position $pos";
12}
1
2<?php
3$mystring = 'abc';
4$findme = 'a';
5$pos = strpos($mystring, $findme);
6
7// El operador !== también puede ser usado. Puesto que != no funcionará como se espera
8// porque la posición de 'a' es 0. La declaración (0 != false) se evalúa a
9// false.
10if ($pos !== false) {
11 echo "La cadena '$findme' fue encontrada en la cadena '$mystring'";
12 echo " y existe en la posición $pos";
13} else {
14 echo "La cadena '$findme' no fue encontrada en la cadena '$mystring'";
15}
16?>
17
18