I would like to check if a given string is a substring to another string. For example:
$a = 'Hello World!';
$b = 'ell';
$b is a substring of $a. Any functions that can check this?
I would like to check if a given string is a substring to another string. For example:
$a = 'Hello World!';
$b = 'ell';
$b is a substring of $a. Any functions that can check this?
You can use strpos()
function to check that
<?php
if (strpos('Hello World!','ell') !== false) {
echo 'contains';
}
else echo 'not contains';
Try this
$a = 'Hello World!';
$b = 'ell';
if (strpos($a, $b) !== false) {
echo true; // In string
}
$mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);
if ($pos === false) {
echo "The string '$findme' was not found in the string '$mystring'";
} else {
echo "The string '$findme' was found in the string '$mystring'";
echo " and exists at position $pos";
}