Home  >  Article  >  Backend Development  >  How to implement regular matching operation in PHP

How to implement regular matching operation in PHP

墨辰丷
墨辰丷Original
2018-05-19 14:22:181501browse

This article mainly introduces the PHP regular matching operation, and combines a simple example to analyze the preg_match_all in PHP to obtain the content of the P element and img src element in the HTML tag. Friends in need can refer to it


          

幸福领地

一世情长

EOT; if(preg_match_all('%(.*?)

%si', $str, $matches)) { $arr[0][] = $matches[1]; } if(preg_match_all('/src="([^<]*)" >/i', $str, $matches)) { $arr[1][] = $matches[1]; } print_r($arr); exit; ?>

The running results are as follows:

Array
(
  [0] => Array
    (
      [0] => Array
        (
          [0] => 幸福领地
          [1] => 一世情长
        )
    )
  [1] => Array
    (
      [0] => Array
        (
          [0] => http://www/template9/yunqingjian/jianjie/68.jpg
          [1] => http://www/template9/yunqingjian/jianjie/69.jpg
        )
    )
)

##Related recommendations:

PHPRegular matchingInstance code of date and time (time stamp conversion)

# #PHP

Regular matchingCauses and solutions for failure of all characters
##PHP simple implementation

Regular matching

Province and city methods

##

The above is the detailed content of How to implement regular matching operation in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn