如何从外部网页加载特定DIV到我网站的特定DIV? [英] How Can I load a specific DIV from an external webpage, into a specific DIV of my website?
本文介绍了如何从外部网页加载特定DIV到我网站的特定DIV?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将外部网页的特定Div加载到我自己网站的特定Div(无iframe)中。
例如:
我在我自己的网站上有这样一个div:
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>
我也有这个网站: http://www.timeanddate.com/weather/
我想从这个网站加载一个表格(http://www.timeanddate.com/天气/)进入我的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?
推荐答案
<?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:
With the following CSS :
.wa {
margin: 0 auto;
}
.border2 {
background: none repeat scroll 0 0 #D7D6DC;
}
.lpad tr td {
padding: 0.2em;
}
这篇关于如何从外部网页加载特定DIV到我网站的特定DIV?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文