dongwen7371
2012-05-07 17:52如何显示从外部网站获取的内容?
How do I grab pieces of content from external websites and display them on my website? (Similar to what an RSS feed or other aggregator does).
For example, say I want to display items from another website's calendar:
Other website:
<h1>Here's our calendar:</h1>
<div class="calendar_item">
<h2>Boston Marathon</h2>
<p class="date">June 23, 2012</p>
<p class="description">This marathon is 26.2 miles and lots of fun.</p>
</div>
<div class="calendar_item">
<h2>Irish Pub Crawl</h2>
<p class="date">July 17, 2012</p>
<p class="description">Shamrocks and green things are super-fun.</p>
</div>
<div class="calendar_item">
<h2>Tim's Birthday</h2>
<p class="date">August 25, 2012</p>
<p class="description">It's Tim's birthday, yo.</p>
</div>
My website:
<h1>Here's a feed of some calendar items from someone else's website:</h1>
<div class="event_title">Boston Marathon</div>
<div class="event_date">June 23, 2012</div>
<div class="event_description">This marathon is 26.2 miles and lots of fun.</div>
<div class="event_title">Irish Pub Crawl</div>
<div class="event_date">July 17, 2012</div>
<div class="event_description">Shamrocks and green things are super-fun.</div>
<div class="event_title">Tim's Birthday</div>
<div class="event_date">August 25, 2012</div>
<div class="event_description">It's Tim's birthday, yo.</div>
Here's what I've tried (using MAMP):
<?php
$url = "http://example.com";
$page = curl($url);
$pattern = '%
<h2>(.+?)</h2>
%i';
preg_match($pattern,$page,$matches);
print_r($matches);
?>
...which prints:
Array ( )
The tutorials/etc. I've viewed include ambiguous answers like "try cURL". This seems so simple, but I'm a stumped noob.
Thanks in advance, guys :)
- 点赞
- 回答
- 收藏
- 复制链接分享
3条回答
为你推荐
- 安卓app测试获取接口返回数据,然后处理数据,放在一个button点击事件里面 执行顺序有问题?无法获取数据?
- android-studio
- android
- 4个回答
- 高分悬赏:单片机如何接受来自一个设备的触发信号然后控制另一个设备的状态
- c语言
- 3个回答
- 如何显示从外部网站获取的内容?
- curl
- html
- php
- mamp
- 3个回答
- 尝试从url中获取JSON / JSONP数据并将结果显示在html网页上
- json
- html
- javascript
- jquery
- php
- 3个回答
- 用JS写的贪吃蛇,为什么定时器结束后会自动平移一格?
- javascript
- 1个回答
换一换