In the study, a lot of problems need us in practice to constantly solve. When we make the matching of regular expressions in PHP, it is difficult to perform complex matching operations by using only the regular table function under POSIX, then how to implement the multi-line matching of the PHP regular expression.
For example, the entire file, especially multiple lines of text, is matched to find. One way to do this with Ereg () is by branch processing. The example in code 6.5 shows how Ereg () assigns the parameters of the INI file to the array.
Code 6.5 file contents of PHP regular expression multi-line matching
- < ? PHP
- $ rows = file (' php.ini ');//Read the php.ini file into the array
- Looping through
- foreach ($rows as $line)
- {
- If (Trim ($line))
- {
- Writes a matching successful parameter 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 PHP regular expression multi-line matching implementation method, I hope you can have some experience.
http://www.bkjia.com/PHPjc/446248.html www.bkjia.com true http://www.bkjia.com/PHPjc/446248.html techarticle In the study, a lot of problems need us in practice to constantly solve. When we make a match for the regular expression of PHP, we just use the regular table function under POSIX, it's hard to get into ...