Skip to main content
Home
The Baheyeldin Dynasty
The journey for wisdom starts with knowledge
  • Home
  • About
  • Site Map
  • Contact

Code Snippet: Wrapping content from another site on your site

  1. Home

By Khalid on 2005/09/17 - 11:46, last updated 2005/09/25 - 22:30

Some time ago, there was a question on the Drupal forums about wrapping content from another site to your site.

Here is a basic PHP code snippet that would do just that. You may need to fiddle with the HTML to make the paths absolute to the site that you are wrapping.

If you have improvements, please let me know. 

Also, please do not use this to leech content from other sites, and obey their copyright rules. 

Method 1: Using fopen on a URL 

$url = "http://example.com";

$handle = @fopen ( $url, "r" );
if ( $handle ) {
while ( true ) {
$data = fgets ( $handle, 4096 );
print $data;

if ( true == feof( $handle ) ) {
break;
}
}

fclose ( $handle );
}
else {
$result .= t("Could not contact host: ") . $url;
}

Method 2: Using fopen on a URL - more concise way

After writing the above, Drupal hacker par excellance, Karoly Negyesi (a.k.a. chx), found  a much more elegant and simple solution:

$url = "http://example.com/page.html";
print file_get_contents($url); 

This is much less code for sure. 

Method 3: Using IFRAMEs

You can use an IFRAMEs to wrap content from another site, or another application on your site.

To do this, all you need is to paste the following HTML snippet in the block or the node you want. You will have to experiment with the height and width until you get the size that works best for the site you are wrapping.

<iframe
src="http://www.example.com"
Frameborder=0
height="600"
width="640">
</iframe>
Contents: 
Drupal
  • Add comment

Comments

Marco (not verified)

Saving to node

Sat, 2005/12/10 - 22:28

I was thinking of putting this code to practical use -

Perhaps by making a new content type that can do this sort of processing in Method 1.

I wonder if it were possible to implement the code so I could make a new content type when you input the URL to wrap - it would wrap it when you create the content and not every time you load the page, effectively saving the wrapped content into your database.

Can the be easily done?

  • reply

Khalid

Yes, it can be done

Sun, 2005/12/11 - 00:12

Yes, it can be done. The node type would only need to have a URL, and perhaps a title, and the authoring information. There is no need for a body.

The challenge is that if the wrapped page has path names relative to the domain/host name it is wrapped from. In that case, you have to do some adjusting to add that to each href tag.

  • reply

tallship (not verified)

I'm still stumped...

Wed, 2010/07/14 - 04:32

When I go to http://abc.com/node/16/ for example, where I created the node (page), I only see the following in the body of the page:

rel="lightbox" 
src="http://abc.com/stuff/index.php"
Frameborder=0
height="600"
width="640">
  • reply

Pages

  • « first
  • ‹ previous
  • 1
  • 2

Current

Pandemic

  • COVID-19
  • Coronavirus

Search

Site map

Contents

  • Family
    • Khalid
    • Ancestry
    • Extended
  • Friends
  • Nokat نكت
  • Writings
    • Cooking
    • Culture
    • Science
    • History
    • Linguistics
    • Media
    • Literature
    • Politics
    • Humor
    • Terrorism
    • Business
    • Philosophy
    • Religion
    • Children
  • Technology
    • Linux
    • Arabization
    • Drupal
      • Association
    • Software
    • Internet
    • Technology in Society
    • Digital Archeology
    • NCR History
    • MidEast Internet
    • Programming
    • Saudi ISPs
    • Miscellaneous
  • Places
    • Canada
      • Weather
    • Egypt
      • Cuisine
      • Alexandria
      • E.G.C.
    • USA
    • Saudi Arabia
  • Interests
    • Astronomy
    • Fishing
    • Photography
    • Snorkeling
    • Nature
    • Photomicroscopy
  • Miscellany

In Depth

  • al-Hakim bi Amr Allah: Fatimid Caliph of Egypt الحاكم بأمر الله
  • Alexandria, Egypt
  • Arabic on the Internet
  • Articles on the history of Muslims and Arabs in the Iberian Peninsula تاريخ المسلمين و العرب في الأند
  • DIY GOTO Telescope Controller With Autoguiding and Periodic Error Correction
  • E.G.C. English Girls College in Alexandria, Egypt
  • Egyptian Cuisine, Food and Recipes مأكولات مصرية
  • George Saliba: Seeking the Origins of Modern Science?
  • Internet Scams and Fraud
  • Mistaken for an Arab or Muslim: Absurdities of being a victim in the War on Terror
  • Mistaken Identity: How some people confuse my site for others
  • One People's Terrorist Is Another People's Freedom Fighter
  • Overview of Google's Technologies
  • Photomicroscopy
  • Pseudoscience: Lots of it around ...
  • Resources for using Google Adsense with Drupal
  • Rockwood Conservation Area, Southern Ontario
  • Selected Symbolic Novels And Movies
  • Snorkeling the Red Sea near Jeddah
  • Updates and Thoughts on the Egyptian Revolution of 2011

Recent Content

Most recent articles on the site.

  • Evidence Against Ivermectin Efficacy For COVID-19
  • Origin Of COVID-19: Natural Spillover, Lab Leak Or Biological Weapon?
  • Kamal Salibi and the "Israel from Yemen" theory
  • How To Upgrade HomeAssistant Core In A Python Venv Using uv
  • Ancestry - Paternal Side
more

Most Comments

Most commented on articles ...

  • Another scam via Craigslist: offering more than asking price
  • Warning to female tourists thinking of marrying Egyptians
  • Craigslist classified for used car: Cheque fraud scam
  • Winning the lottery scam email: World Cup South African lottery
  • Email Scam: BMW 5 Series car and lottery winning
more

About Khalid

Various little bits of information ...

  • Khalid Baheyeldin: brief biography
  • Presentations and Talks
  • Youtube Videos
  • GitHub Projects
  • Drupal.org Profile
  • Astrophotography @ Flickr

Sponsored Links

Your Link Ad Here

Tags

Android Mobile Ubuntu Sony OnStep OpenWRT Router Ericsson COVID-19 Rogers Coronavirus Arabic Kubuntu Home Assistant GSM Telescope tablet Spectrum Scam Python 419 Laptop Firefox DIY CPU Conspiracy Comet Balkanization backup App
More

© Copyright 1999-2025 The Baheyeldin Dynasty. All rights reserved.
You can use our content under the Terms of Use.
Please read our privacy policy before you post any information on this site.
All posted articles and comments are copyright by their owner, and reflect their own views and opinions, which may not necessarily be consistent with the views and opinions of the owners of The Baheyeldin Dynasty.

Web site developed by 2bits.com Inc.