繁体   English   中英

用正则表达式匹配网站的一部分

[英]Matching part of website with a regexp

通过cURL请求,我将完整的网站加载到变量:$ buffer中。

在网站的来源中,我的相关内容位于两个标签之间。

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

我一直在忙于preg_match及其正则表达式。 有人可以帮我吗?

提前感谢。

// edit $ buffer是此文本文件: http : //www.rp-systeem.nl/rps/code.txt我想将103减为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]);

?>

上面的片段打印( 如ideone.com上所示 ):

   this part I want to store in a match

您要匹配的部分被捕获为组1。模式中没有什么特别之处,除了它处于单行模式之外. 匹配所有内容(以防万一您有多行)。

参考文献

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM