PHP preg_match函数:如何为preg_match编写真正的模式?

PHP preg_match函数:如何为preg_match编写真正的模式?,php,preg-match,simple-html-dom,Php,Preg Match,Simple Html Dom,我试图将外部网页的特定div加载到我网站的特定div,因此我使用了preg\u match函数来获取部分代码。 但我认为我写错了模式。 这是我的代码: <?php include("simple_html_dom.php"); $html = new simple_html_dom(); $url = "http://something.com/"; $page_all = file_get_contents($url); preg_match('#<tabl

我试图将外部网页的特定
div
加载到我网站的特定
div
,因此我使用了
preg\u match
函数来获取部分代码。 但我认为我写错了模式。 这是我的代码:

<?php
include("simple_html_dom.php");
$html = new simple_html_dom();


   $url = "http://something.com/";
   $page_all = file_get_contents($url); 
   preg_match('#<table id="table1"><table id="table1"><table id="table2">(.*)</table></table></table>#ms', $page_all, $div_array);

   echo ($div_array[0]);
?>

正则表达式中的某些字符具有特殊含义,因此必须对其进行转义。
特殊字符包括:

. \ + * ? [ ^ ] $ ( ) { } = ! < > | :
\+*?[ ^ ] $ ( ) { } = ! < > | :

您可以使用preg_quote自动转义它们。

严重。@deceze您是否希望xml解析器读取包含多个html标记的文档?顺便说一句,如果你没有拥有这个页面,也没有要求页面的所有者使用它的一部分,那么这就是你想要做的。你已经在脚本中要求并实例化simple_html_dom了。你为什么不用它来找到你正在寻找的元素呢?@deceze链接页面的源代码是垃圾。XML解析是不可能的。@Meghdad Hadidi我不希望该页面的所有者希望您使用他的数据。这就是为什么我不会直接帮助你。寻找一些Web服务以合法获取数据。请进一步解释如何在blow code中为extract
table2
编写真实模式: