• preg_match_all() -
This function is similar to preg_match(); however, rather than searching for just
one occurrence of the search parameter, this function will find all occurrences. In addition, each
occurrence found will be placed into an array variable entered into the third input parameter. The
array created will contain various sections of the subpatterns contained in the search pattern. Just like
preg_match(), if there is a match, the function returns a TRUE, if the regular expression does not
find a match, a FALSE is returned.
<?php
$text = "mysql_close, mysql_connect and mysql_error are
all PHP functions used when working with MySQL.";
if (preg_match_all("/mysql\w+/",$text,$mysql_commands) {
print_r($mysql_commands);
} else {
print "No mysql commands were found";
}
?>
• preg_quote() -
This function places a backslash in front of all special regular expression characters.
This is useful if a run-time string containing special regular expression characters has to be evaluated.
The special regular expression characters are: . \ + * ? [ ^ ] $ ( ) { } = ! < > | :
<?php
$text = "The rental is $300";
print preg_quote($text); // Returns "The rental is \$300"
?>
Comments
Post a Comment