Explain the example code of PHP regular expression multi-line matching. In the course of study, many problems need to be solved continuously in practice. When matching PHP regular expressions, we only use regular expression functions under POSIX, which is difficult to learn. many problems need to be solved continuously in practice. When matching PHP regular expressions, we only use regular table functions under POSIX, which makes it difficult to perform complex matching operations. how can we implement multi-row matching of PHP regular expressions.
For example, search for the entire file (especially multi-line text. One way to use ereg () to perform this operation is to handle it by a branch. The sample code 6.5 demonstrates how ereg () assigns the INI file parameters to an array.
PHP regular expressions in code 6.5 file content match multiple lines
- <? Php
- $ Rows = file ('php. ini '); // read the php. ini file to the array.
- // Loop traversal
- Foreach ($ rows as $ line)
- {
- If (trim ($ line ))
- {
- // Write matched parameters to the array
- If (eregi ("^ ([a-z0-9 _.] *) * = (. *)", $ line, $ matches ))
- {
- $ Options [$ matches [1] = trim ($ matches [2]);
- }
- Unset ($ matches );
- }
- }
- // Output parameter results
- Print_r ($ options );
- ?>
The above code example is the specific implementation method of PHP regular expression multi-line matching. I hope you will understand it later.
Bytes. When matching PHP regular expressions, we only use regular table functions under POSIX, which is hard to get...