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
精彩评论