Home
Home Page
Krossbrauzernoe alignment on the center (table height=100 %)
Lists a la MS Word
Features of links « upwards pages »
Tables and borders
We get rid from cellpadding and cellspacing
Optimum use MySQL
Competent job with files: exclusive blocking of files
How to learn{find out} the size of a file on any web - server
Regular expressions
Processing of lines in RNR
Creation of system of the account of visitings
Tracking a content on dynamic sites
CSS: advice{councils} and receptions, a part 2
CSS: advice{councils} and receptions, a part 1
Ten rules of a spelling of a safe code on PHP
About tags and metatags
Potential vulnerability of php-scripts
Removal{Distance} of a line from a file
The generator of passwords
Links
 

Regular expressions

What is the regular expressions?


Regular expressions - cherezvychajno the powerful tool of job with lines. With their help it is possible to spend the analysis and change of lines on the basis of the set pattern.


Let's consider simple (it is far from being all) rules of formation of a pattern.


Pattern sostovljaetsja from a set of modifiers, some of which are resulted in the below-mentioned table.

\ - the Following symbol is special. As it is applied to the instruction{indication} of symbols which can be used as modifiers.         \n - corresponds{meets} to a symbol of translation of a line

\* - a symbol "*", and * - the modifier

^ - the Marker of the beginning of a line.         ^abc - a line beginning with "abc".

$ - the Marker of the end of a line.         abc $ - a line which is coming to an end on "abc".

* - the previous symbol meets 0 or more times.         To a pattern w* there correspond{meet} lines what, buka, agwt

+ - the Previous symbol meets 1 or more time.         To a pattern w + there correspond{meet} lines what, agwt.

The line buka any more does not correspond{meet}.

? - the Previous symbol meets 0 or 1 time.         To a pattern w? r there correspond{meet} lines ara, awra.

- Corresponds{Meets} to any symbol which is distinct from "\n."         


These are the elementary modifiers which knowledge while will suffice us.


In PHP there are some functions for job with regular expressions: ereg (), ereg_replace (), eregi (), ereg_replacei () and split ().


Functions with a suffix i are analogues of functions without this suffix, not chuvstvtitel`nye to the register of operands.


Let's consider function ereg (), which syntax:



int ereg (string pattern, string string, array [regs]);


Let's consider some address maxx@mail.ru. It is obvious, that the plausible address should look like "slovo@slovo.slovo". In terms of patterns the any symbol is designated is familiar "." (we shall not take into account now that fact, that in addresses all symbols) are allowable not. In each word there should be at least one symbol, thus, the pattern of a word looks like ". + ". We shall recollect now, that "." Is a modifier, and for the obvious instruction{indication} of a point (as a symbol) it is necessary to write " \. ".


Thus the pattern will look like ". +. + \.. + ".


Our check will have the following kind:



if (ereg (". +. + \.. + ", $email)) {

echo " the Address, like, correct ";

}

else {

echo " Enter, baten`ka, the address anew ";

}


After such check we can be sure, that e-mail the address looks like "slovo@slovo.slovo".