如何将外部网页中的特定DIV加载到我网站的特定DIV中?

时间:2011-11-17 07:18:55

标签: html load external webpage

我想将外部网页的特定Div加载到我自己网站的特定Div(No iframe)中。 例如: 我在自己的网站上有这样的div:

<div id="weather-status"> Weather Status </div>

我也有这个网站:http://www.timeanddate.com/weather/ 我想从这个网站(http://www.timeanddate.com/weather/)加载一个表到我的div(天气状态) 我该怎么做?

1 个答案:

答案 0 :(得分:1)

<?php
   $url = "http://www.timeanddate.com/weather/";
   $page_all = file_get_contents($url); 

   preg_match('#<table class="border2 lpad wa">(.*)</table>#ms', $page_all, $div_array);


   echo "<pre>";
   print_r($div_array[0]);
   echo "</pre>";
?>

使用以下CSS:

.wa {
    margin: 0 auto;
}

.border2 {
    background: none repeat scroll 0 0 #D7D6DC;
}

.lpad tr td {
    padding: 0.2em;
}
相关问题