开发者

Matching part of website with a regexp

开发者 https://www.devze.com 2023-01-02 06:17 出处:网络
With a cURL request I load a complete website into a variable: $buffer. In the source of the site there are two labels in between which my relevant content is placed.

With a cURL request I load a complete website into a variable: $buffer.

In the source of the site there are two labels in between which my relevant content is placed.

****** bunch of code *******
<!-- InstanceBeginEditable name="Kopij" -->
       this part I want to store in a match
<!-- InstanceEndEditable -->
****** bunch of code *******

I've been messing around with开发者_开发问答 preg_match and its regexp. Can someone try to help me?

Thanx in advance.

//edit The $buffer is this text file: http://www.rp-systeem.nl/rps/code.txt I want to substract 103 to 176


<?php

$buffer = <<<EOT

****** bunch of code *******
<!-- InstanceBeginEditable name="Kopij" -->
       this part I want to store in a match
<!-- InstanceEndEditable -->
****** bunch of code *******

EOT;

preg_match('/<!-- InstanceBeginEditable name="Kopij" -->(.*)<!-- InstanceEndEditable -->/s', $buffer, $match);

print_r($match[1]);

?>

The above snippet prints (as seen on ideone.com):

   this part I want to store in a match

The part that you want to match is captured as group 1. There's nothing special in the pattern, except that it's in single-line mode so . matches everything (just in case you have multiple lines).

References

  • preg_match
  • http://www.regular-expressions.info/
    • The Dot Matches (Almost) Any Character
    • Grouping
0

精彩评论

暂无评论...
验证码 换一张
取 消