Interpretation of PHP regular expression multi-line matching example code _ PHP Tutorial

Source: Internet
Author: User
Tags ereg
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

 
 
  1. <? Php
  2. $ Rows = file ('php. ini '); // read the php. ini file to the array.
  3. // Loop traversal
  4. Foreach ($ rows as $ line)
  5. {
  6. If (trim ($ line ))
  7. {
  8. // Write matched parameters to the array
  9. If (eregi ("^ ([a-z0-9 _.] *) * = (. *)", $ line, $ matches ))
  10. {
  11. $ Options [$ matches [1] = trim ($ matches [2]);
  12. }
  13. Unset ($ matches );
  14. }
  15. }
  16. // Output parameter results
  17. Print_r ($ options );
  18. ?>

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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.