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

vrob (not verified)

I tried the iframe and I get

Sat, 2005/10/29 - 22:18

I tried the iframe and I get the following php error: Parse error: parse error, unexpected '<' in /home/.../drupal-4.6.3/includes/common.inc(1857) : eval()'d code on line 2

Any ideas?

I tried the other snippets and the css gets messed up on my main drupal content. It seems to want to add the wrapped page's css into my drupal css or something...

  • reply

Khalid

What format?

Tue, 2005/11/15 - 22:26

Did you use PHP format? Just use HTML.
--
Khalid Baheyeldin

  • reply

bomarmonk (not verified)

I-frame in drupal node

Tue, 2005/12/27 - 16:56

I'm trying the iframe snippet, but I'm also getting the unexpected "<" error. I have the php input format selected and I've added closing and opening php tags to the code.

  • reply

Khalid

Contact me

Wed, 2005/12/28 - 12:12

Go to the feedback form and copy/paste the code you are trying, and I will look into it, and reply by email.

  • reply

Anonymous (not verified)

Code Snippet:Wrapping content from another..

Wed, 2006/05/24 - 21:00

Can you help me...

I have tried the PHP method (gives me nothing but code, even when set to PHP code) and the Iframe method to capture and display another (exterior) web page within my Drupal site. I am using the adc theme.

The Iframe method seems to work fine in FireFox but in IE the node overshoots the right side...falling under the blocks on the right column of the page.

See what I mean...

http://reelorbit.com/node/27/

Please advise...

  • reply

Khalid

CSS issue

Wed, 2006/05/24 - 21:19

Looks like a CSS issue. Try another theme and see if it works or not. If it does, then it an adc specific CSS bug.

  • reply

bomarmonl (not verified)

Works!

Thu, 2005/12/29 - 13:40

Thanks for the help. It works now. I didn't realize I wasn't supposed to wrap the i-frame in php tags. Without those php tags, it functions perfectly!

  • reply

putri (not verified)

Where do you plug all this in?

Wed, 2005/12/07 - 12:11

This is what I need but I have no clue where to input all this code in. New to Drupal.

Thanks!

  • reply

Khalid

In a node

Wed, 2005/12/07 - 13:15

Create a node, set the input format to PHP code, and paste the code in it.

  • reply

tallship (not verified)

I created a node (page) and don't see some of the options...

Wed, 2010/07/14 - 04:22

I did "create content" ==> "page" and chose "full HTML" instead of "filtered HTML". I didn't see an option for setting the input to PHP code.

I also tried to create a node via views. Still didn't see the option. Can you provide a little more info on how to create this node, which I'm going to select as having the input format of "PHP code"?

Thanks :)

  • reply

Pages

  • 1
  • 2
  • next ›
  • last »

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.

  • 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
  • Review of Wait Water Saver For Whole House Humidifiers
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.