Interpreting PHP Regular expression multi-line matching code example _php tutorial

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

 
  1. < ? PHP
  2. $ rows = file (' php.ini ');//Read the php.ini file into the array
  3. Looping through
  4. foreach ($rows as $line)
  5. {
  6. If (Trim ($line))
  7. {
  8. Writes a matching successful parameter 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 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 ...

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