preg_replace_callback

(PHP 4 >= 4.0.5, PHP 5, PHP 7) Perform a regular expression search and replace using a callback mixed preg_replace_callback ( mixed $pattern, callable $callback, mixed $subject [, int $limit = -1 [, int &$count ]] ) The behavior of this function is almost identical to preg_replace(), except for the fact that instead of replacement parameter, one should specify a callback. Parameters:

preg_replace_callback_array

(PHP 7) Perform a regular expression search and replace using callbacks mixed preg_replace_callback_array ( array $patterns_and_callbacks, mixed $subject [, int $limit = -1 [, int &$count ]] ) The behavior of this function is similar to preg_replace_callback(), except that callbacks are executed on a per-pattern basis. Parameters: patterns_and_callbacks An associativ

preg_quote

(PHP 4, PHP 5, PHP 7) Quote regular expression characters string preg_quote ( string $str [, string $delimiter = NULL ] ) preg_quote() takes str and puts a backslash in front of every character that is part of the regular expression syntax. This is useful if you have a run-time string that you need to match in some text and the string may contain special regex characters. The special regular expression characters are: . \

preg_match

(PHP 4, PHP 5, PHP 7) Perform a regular expression match int preg_match ( string $pattern, string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] ) Searches subject for a match to the regular expression given in pattern. Parameters: pattern The pattern to search for, as a string. subject The input string.

preg_match_all

(PHP 4, PHP 5, PHP 7) Perform a global regular expression match int preg_match_all ( string $pattern, string $subject [, array &$matches [, int $flags = PREG_PATTERN_ORDER [, int $offset = 0 ]]] ) Searches subject for all matches to the regular expression given in pattern and puts them in matches in the order specified by flags. After the first match is found, the subsequent searches are continued on from end of the

preg_last_error

(PHP 5 >= 5.2.0, PHP 7) Returns the error code of the last PCRE regex execution int preg_last_error ( void ) Returns the error code of the last PCRE regex execution. Example #1 preg_last_error() example <?php preg_match('/(?:\D+|<\d+>)*[!?]/', 'foobar foobar foobar'); if (preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR) {     print 'Backtrack limit was exhausted!'; } ?> The above example will output:

preg_grep

(PHP 4, PHP 5, PHP 7) Return array entries that match the pattern array preg_grep ( string $pattern, array $input [, int $flags = 0 ] ) Returns the array consisting of the elements of the input array that match the given pattern. Parameters: pattern The pattern to search for, as a string. input The input array. f

preg_filter

(PHP 5 >= 5.3.0, PHP 7) Perform a regular expression search and replace mixed preg_filter ( mixed $pattern, mixed $replacement, mixed $subject [, int $limit = -1 [, int &$count ]] ) preg_filter() is identical to preg_replace() except it only returns the (possibly transformed) subjects where there was a match. For details about how this function works, read the preg_replace() documentation. Retur

Perl Differences

Pattern Modifiers

Examples: Use of this modifier is discouraged, as it can easily introduce security vulnerabilites: <?php $html = $_POST['html']; // uppercase headings $html = preg_replace(     '(<h([1-6])>(.*?)</h\1>)e',     '"<h$1>" . strtoupper("$2") . "</h$1>"',     $html ); The above example code can be easily exploited by passing in a string such as <h1>{${eval($_GET[php_code])}}</h1>. This gives the attacker