How great and diverse is the world of information,so rapidly it expands and develops. Any solution is just a moment in the general process of motion. Knowledge and experience make it possible to understand the process of achieving the goal, but never - not the result of achieving it. It is doubtful that in the foreseeable future it is generally possible to talk about the result, but it is very important that the process of striving for it is an essential and objectively necessary process.
"Desire and / or big money" does not createan algorithm capable of what a person does naturally and "free", especially when he does not think about what he is doing. In any position of the information problem, there is at least one white spot, but behind it, usually immediately, other blank spots are visible, and it is not necessarily that they are all white.
Internet technologies have greatly simplified accessto information, but the question - how to impose on the desired one - was not simplified, but acquired new "volumes" of work. And although in PHP regular expressions the gap is clearly not exhausted, they are a significant step forward.
By offering regular expressions, PHP is essentialreduces the content of the algorithm, but the usual search / replace functions and processing algorithms found have not lost their value. New ideas do not foreshow the information revolution. The maximum you can count on is a compact code and the developer's ability to correctly formulate a search query.
You should know and apply regular PHPexpression. The examples are convincing and effective. But it should be reported that with the advent of the new search engine, the center of gravity has shifted to a template - a kind of mechanism, although in effect it replaces many simple search functions, conditions, cycles, and other operators.
Have:
Achieving knowledge, as it was necessary to understand the problem, in order to solve it, often has more significance than a specific result.
Regular expressions in PHP are representedseveral functions in the syntax of the language and many useful examples on the Internet. Due to the specifics of the syntax of the language, the application options are limited only by the imagination of the developer, however, it should be noted that not all templates will work. With PHP, checking regular expressions is essential.
A symbol is not always one byte, and often a character,as an elementary signal, carries an exact meaning in addition. The encoding defines the visible characters in the code in different ways. The symbol can have several variants: "$" = "USD" = "cu", ... is the exact meaning that somewhere somewhere, but not necessarily nearby, is connected with the currency. However, the exact meaning can also lie in the PHP variable, which always starts with the "$" symbol, but can not begin with "USD" and "cu".
In programs, a symbol can be a function name(string) in context: recognize and execute is from the field of dynamic object-oriented programming, where PHP constructs, functions, regular expressions are used directly for decision making. The found symbol is "executed", that is, it determines by itself what to do in the place where it is found, and how it "deems it" necessary.
Finding just a character / string is not so simpleoccupation, and the more in the information symbol, the better. Do not always need to find a dozen of the best food prices, choose delicious recipes for a holiday cake or decide on a contractor for a suspended ceiling.
Often we have to optimize simple algorithmswith not simple information arithmetic or in difficult conditions, when the desired symbol should be selected from the database, and the line in which it should be found - in a hundred sites. In this case, the price of choosing a symbol is equal to the time of sampling from the database, and the price of where to look for is the search time of the notorious hundreds of sites.
A lonely symbol is not a phrase or a few phrases, it can be anywhere and be arbitrarily small. How to determine what exactly is found is what you are looking for?
Just find the symbol "$" in the text - a little. Check that there is a figure before it, too, is not always enough. If you provide a point or figure before the symbol "$", it is a guarantee that the prices, in which the money symbols are in front, will not be taken into account. Prices will also be missed, in which the currency is not indicated at all, but there is an explicit indication on the page.
In general, the solution of the problem in the usual way inflates the algorithm beyond recognition and will take a lot of time. Meanwhile, using a regular expression, the number of PHP will find no problems.
$ cContents = preg_match_all ("/ [0-9] + ([\ $] | usd | у \. e \. | уе) {1} / i";
"look e-mail - 2usd; <br/>";
"find e-mail - 2e, <br/>";
"work e-mail - уе2; <br/>";
"check e-mail - $ 13", $ aResult);
. ";". implode (",", $ aResult [0]). "<br/>".
The answer is: "2; 2usd, 2u.e.", but will not find anything in the line: "check e-mail - $ 13".
Provided in the template the presence of a symbol in front or behind, you can quickly reach the goal in the vast majority of cases.
$ cContents = preg_match_all ("/ ([0-9] + ([\ $] | usd | y \. e \. | ye) {1}) | (([$] | usd | y |. e |. | ye) {1} [0-9] +) / i ";
"look e-mail - 2usd; <br/>";
"find e-mail - 2e, <br/>";
"work e-mail - уе2; <br/>";
"check e-mail - $ 13", $ aResult);
. ";". implode (",", $ aResult [0]). "<br/>".
The result: "4; 2usd, 2u.e., ye2, $ 13".
Regular expressions PHP offers, like the otherstools, but it is not at all necessary to use them according to its rules or to use other inline functions provided in the syntax way.
You can turn what you are looking for before you start the search.array, and the place where the search will be performed, divided into components according to the preliminary criterion. A simple pair of explode () and implode () functions often simplifies and speeds up the solution.
For example, as a result of preliminary workAn array of rows (data) has been generated in the district about how many villages each village has collected: the Name of the Village and the amount collected, and if there are several enterprises in the village, then the Name of the Tree is on the string of the array. The name of the Enterprise and the value through ";" and so on all enterprises. It is not possible to calculate the total amount collected in this case, but if you make impode (";", $ aResult), there will be one long line in which the pairs - Name Tree / Name Tree. The name of the Enterprise - the collected volume - will be listed through ";". Having done the reverse on the received, explode (";", $ aResult) - an array of all who collected and how much it collected, then, removing all non-numeric characters from the lines, we have only digits, the sum of which is the total volume of the collected.
In this example, regular expressions in PHPThey do not need to look for anything superfluous, they simply and easily extract the necessary numerical values. Quickly and effectively, no matter how long the names of the villages and businesses are. This decision is not ideal, but it shows that not always it is necessary to follow the rules. It is often possible to achieve the desired in an unusual way.
The syntax of the algorithm does not say how it islooks really. But, providing the same encoding of the page, script and lines (which is searched and in which the search is performed), you can immerse yourself in the task outside its technical side.
It is necessary not only to know what to look for, but also where it isdo, when, in what quantity, what to change and how. Formally, regular PHP expressions are executed as a complete, complete, fully functional mechanism, but for many reasons the implementation of its counterparts in different languages is different. As a general rule, before you can transfer a template to one or another tool environment for a specific task, you need to perform a qualitative adaptation, perform a check on all possible variants of the original data.
Even if you use your own experiencePHP-based development, regular expressions, examples, templates and constructs require close verification. The language functional, its syntax and the execution environment dynamically change.
What was previously written in the form of a combinationsearch functions, conditional operators, replace operations, insertion, deletion, is a single string of characters according to certain rules - a regular expression pattern. In fact, a significant volume is coded in a strictly defined way and is executed according to specific rules.
Just as you can not debug anyoperator of the language, so you can not debug a regular expression pattern, this process can only be emulated. As a general rule, the option is accepted: it works - it does not work. The syntax is very simple, although its perception, especially at the beginning of the work, is very difficult.
In a simple version, the pattern matches the line:
$ cContents = preg_match ("/ asdf / i", "asdf", $ aResult). ";". implode (",", $ aResult).
The result is "1; asdf", since the functionfinishes its work on the first encountered pattern match. The result will be the same if you look in the line "aaaasdf" and in the line "zzzasdfvvv". If you specify the first and / or last character, the result will be unambiguous:
$ cContents = preg_match ("/ ^ asdf / i", "asdf", $ aResult). ";". implode (",", $ aResult). "<br/>";
$ cContents. = preg_match ("/ asdf $ /", "asdf", $ aResult). ";". implode (",", $ aResult). "<br/>".
The result will be: 1; asdf1; asdf.
The symbols "^" and "$" indicate where to starttemplate and how it ends. The result of the preg_match function is the number of matches, it can be 0, 1 or false if an error is detected. The third parameter is an array - the only element found is located. If you use the preg_match_all () function, the search continues to the end of the line.
$ cContents = preg_match ("/ asdf / i", "asdf123asdf456asdf789", $ aResult). ";". implode (",", $ aResult). "<br/>";
$ cContents. = preg_match_all ("/ asdf / i", "asdf123asdf456asdf789", $ aResult). ";". implode (",", $ aResult [0]). "<br/>".
Result:
1; asdf
3; asdf, asdf, asdf.
If you do not use special instructions, theneach character defines itself and its place, regardless of the character encoding of the string and the encoding of the template. The programmer is obliged to take care that the encodings of these elements are correct relative to each other and the encoding of the page.
Regular expressions in PHP representstrings of characters written in a certain way. Usually, by analogy with other programming languages, they are written in the characters "/" ... "/" and placed in quotation marks, depending on the algorithm you can use single and double.
The main function of php preg match is regularthe expression uses as a pattern match and stops when it first finds it, its variant with the _all suffix looks for all matches and produces an array of those. The preg replace function replaces each matching pattern match, it can work with arrays, allowing you to design a search and perform a replacement for a variety of options.
Interesting options for working with regularexpressions can be developed using the function preg_replace_callback, which takes no text to replace, but the name of the function that will perform such a replacement. In addition to the practical value, you can implement template validation mechanisms, which plays an important role in developing and debugging the latter.
Because hypertext languages areformalized information, to a greater extent they are the source material. A large number of templates and designs have been developed that can effectively process large amounts of information. A significant part of this work is done by mechanisms built into various content management systems (CMS).
Not surprisingly, many CMS have become standardsde facto for building sites, and, being accompanied by (updated) development companies, they do not need to perform the development of templates on their own. However, outside of such systems, having experience with regular expressions is very useful.
An important area of application of regular expressions onPHP is formed by the appearance of PHPOffice libraries. Work with documents and spreadsheets has always been and is important, and the OOXML standard allowed not only to disassemble the real documents, but also to create them programmatically.
Thanks to the development of hypertext and PHP inIn particular, there is a real opportunity to automate the "production" of documents of the "standard form", for example, bills for payment, reports, business plans and other information objects whose structure and content are really amenable to formalization and automation.
In connection with the application to describe the language OOXMLthe process of developing regular expressions has significant differences from the traditional work with markup languages HTML and CSS in the first place. A real document, besides markup and in addition to the actual content itself, has many details. For example, a document created automatically by the program will have strict and precise content. A document formed by a person or processed by it will have content written on a set of tags. Any work with the document leads to the fact that the semantics of it can remain one, but painted inside by a different number of different designs.
A person is always interested in solving a problem,the production of which is information and, as a result, information will also be given. Having presented the statement of the problem in the form of a document, a person receives a certain semantics, which during the specification by specialists (making changes, clarifying the wording, deleting, editing) leads not only to a variety of variants of one document, but also to versions with different content.
In particular, the task set by the phrase "Resolvesquare editing ", after editing it will not look like this:" Solve the quadratic equation. "If the first error was corrected first and then the second one, then the natural information in the OOXML style can look like:" [Solve] [] [square] [e] [] [hurray] [to] [tion] ", but this is not at all a guarantee that this is how the task will look in the OOXML tags (square brackets emulate the parentheses of the tags).
Collect the information together easily afterEach process of task editing, but each time this procedure will be performed by a different algorithm. Regular expressions, as a kind of tool for formalizing information tasks, have become, in fact, a path from formal hypertext structures to natural information.
</ p>