How Can I load a specific DIV from an external webpage, into a specific DIV of my website?

谁说胖子不能爱 提交于 2019-11-30 21:01:02

问题


I Want to load a Specific Div of an external webpage into a specific Div (No iframe) Of my own website. for example: I have a div like this in my own website:

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

I have this site too: http://www.timeanddate.com/weather/ and I want to load a table from this site (http://www.timeanddate.com/weather/) into my div (Weather Status) How Can I Do This?


回答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>";
?>

With the following CSS :

.wa {
    margin: 0 auto;
}

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

.lpad tr td {
    padding: 0.2em;
}


来源:https://stackoverflow.com/questions/8163412/how-can-i-load-a-specific-div-from-an-external-webpage-into-a-specific-div-of-m

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!