php match code example
Example 1: preg_match in php
<?php
$str = "Check For Testing.";
if (preg_match("/\bCheck\b/i", $str, $match))
echo "Matched!";
else
echo "not matched";
?>
Example 2: string match in php
if (str_contains('Foo Bar Baz', 'Foo')) {
echo 'Found';
}
Example 3: preg_match
if(!preg_match('/^\[a-zA-Z]+$/',$input)) {
}
Example 4: preg_match in php
<?php
$my_email = "[email protected]";
if (preg_match("/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/", $my_email)) {
echo "$my_email is a valid email address";
}
else
{
echo "$my_email is NOT a valid email address";
}
?>
Example 5: find substring regx php
if (preg_match("/\bweb\b/i", "PHP is the web scripting language of choice.")) {
echo "A match was found.";
} else {
echo "A match was not found.";
}
Example 6: php regex
preg_match('/(foo)(bar)(baz)/', 'foobarbaz', $matches, PREG_OFFSET_CAPTURE);