Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.

preg_check

Searches value for a match to the regular expression given in expression. This function is identical to the preg_match() fucntion except this will return false it the $value is an array.

preg_check

Quote

preg_check ( string $expression, mixed $value )


Parameters
expression
The expression to search for, as a string.

value
The input string.

Return Values
preg_check() returns the number of times expression matches. That will be either 0 times (no match) or 1 time because expression() will stop searching after the first match.
expression() returns FALSE if an error occurred or the value is an array!

Examples

preg_check() alphanumeric
Code
<?php
$value = "123abc"
if (preg_check("/^[0-9A-Za-z]+$/", $value)) {
 echo "The string only contains alphanumeric chars.";
} else {
 echo "The string contains non alphanumeric chars.";
}
?>

Here we will check if the string $value only contains alphanumeric chars

Output from the above example

Quote

The string only contains alphanumeric chars.


preg_check() array
Code
<?php
$value = array("123abc");
if (preg_check("/^[0-9a-z]{32}$/", $value)) {
 echo "The string only contains alphanumeric chars.";
} else {
 echo "The string contains non alphanumeric chars.";
}
?>
Here the preg_check() function will return false as the $value is an array

Output from the above example

Quote

The string contains non alphanumeric chars.


Notes
If you only want to check if one string is contained in another string, you can use strpos() or strstr() as they are be faster.