-1
我试图将外部网页的特定div
加载到我网站的特定div
所以我使用preg_match
函数来获取部分代码。 但我认为我写错了模式。 这是我的代码:PHP preg_match函数:如何为preg_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]);
?>
我想要得到的第二table
的内容与id=table2
在http://somthing.com 那么它was'nt有任何结果。
[您是否尝试过使用XML解析器呢?(http://stackoverflow.com/a/1732454/476)严重转义。 – deceze
@deceze你期望XML解析器读取具有多个HTML标签的文档吗?顺便说一下,如果你不拥有这个页面,也没有要求页面的所有者使用它的一部分,这是你想要做的事。 – rekire
您已经在脚本中要求并实例化simple_html_dom。你为什么不用它来找到你要找的元素? – VolkerK