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$haystack = 'This is my haystack that we shall check'
2$has_A = strpos($haystack, 'A') !== false;
3$has_a = strpos($haystack, 'a') !== false;
4
1// if you want to test content of a string to match a model
2
3//You should use a regex filter with preg_match who returns 1 or 0
4
5// this filter works for most of cases
6
7/* use this regex */ preg_match("/^[a-z ,.'-]+$/i", your_string);
8
9if you want more regex filters you can make yours on 'https://regex101.com/'