HOME
PHP
Introduction Php Installation
PHP Basic Scripts
PHP variables
PHP operators
PHP Conditional statement
PHP functions
PHP Arrays
PHP Objects & classes
PHP with Forms
PHP Files
PHP With Database
PHP session
PHP cookies
PHP Regular Expressions
PHP Server Environment
PHP Graphics
PHP Advance
|
Regular expression
Regular expression are a powerfull way of examining and modifying text.they enable you to search for
patter witinh string ,extracting matches flexibly and precisely.hey are most powerfull ,they are also slower than the basic string function.PHP support
two flavours of regular expression.IT has a set of functions that emulate regular expressions as employed in perl and a set of functions that emulate
regular expression as employed in PERL. and a set of function that support the more limited POSIX regular expressions.
POSIX regular expression
POSIX Regular expression functions make it mossible for you to match and replace complex pattern in strings.they are commonly known simply as regular expression functions.
ereg() ------------>requires a string representing a pattern, astring representaining the text to be searched,and anarray variable into which the results of the search will be placed.ereg() returns an integer representing the number of characters matched if the pattern was discovered in the source string,or false otherwise.
preg_match()--------->Like the ereg function, bool preg_match (string pattern, string subject [, array groups]) returns TRUE if the regular expression pattern matches the subject string or part of the subject string. If you specify the third parameter, preg will store the substring matched by the part of the regular expression between the first pair of capturing parentheses in $groups[1]. $groups[2] will contain the second pair, and so on.
preg_match_all()------->int preg_match_all (string pattern, string subject, array matches, int flags) fills the array "matches" with all the matches of the regular expression pattern in the subject string. If you specify PREG_SET_ORDER as the flag, then $matches[0] is an array containing the match and backreferences of the first match, just like the $groups array filled by preg_match. $matches[1] holds the results for the second match, and so on. If you specify PREG_PATTERN_ORDER, then $matches[0] is an array with full subsequent regex matches, $matches[1] an array with the first backreference of all matches, $matches[2] an array with the second backreference of each match, etc.
array preg_grep------> (string pattern, array subjects) returns an array that contains all the strings in the array "subjects" that can be matched by the regular expression pattern.
Like ereg_replace, mixed preg_replace (mixed pattern, mixed replacement, mixed subject [, int limit]) returns a string with all matches
of the regex pattern in the subject string replaced with the replacement string. At most limit replacements are made. One key difference is that all
parameters, except limit, can be arrays instead of strings. In that case, preg_replace does its job multiple times, iterating over the elements in the
arrays simultaneously.
will produce
Array
(
[0] => Array
(
[0] => def
[1] => 0
)
)
Example 1. ereg_replace() example
for more information about the PHP regular expression click here
< href="http://us3.php.net/manual/en/ref.regex.php">php manual
|
|
|
|