preg_match
Performs a regular expression match against a string and returns whether a match was found.
Parameters
main.php
Return Values
int|false
Returns 1 if the pattern matches, 0 if it does not, or false on error
On success:1 if pattern matches the subject string
On failure:0 if no match found, false if error occurred
Notes
- Function is case-sensitive unless 'i' modifier is used in pattern
- Use strict comparison (===) to distinguish between 0 and false
- Pattern must be enclosed in delimiters (e.g., '/pattern/')
- If matches array is provided, it will contain captured groups
Changelog
- 8.0.0: Passing a needle that is not supported by the haystack will now throw a TypeError
Related Functions
preg_replace
RegExPerforms a regular expression search and replace operation on a string or array of strings.
regexpatternreplace
strlen
StringReturns the length of a string in bytes.
lengthvalidationsecurity
is_array
VariableChecks whether a variable is an array.
validationtype-checksafety
isset
VariableDetermines if a variable is declared and is different than null.
checkvalidationsafety
empty
VariableDetermines whether a variable is empty. A variable is considered empty if it does not exist or if its value equals false.
validationcheckinput