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>
Comments
vrob (not verified)
I tried the iframe and I get
Sat, 2005/10/29 - 22:18I 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...
Khalid
What format?
Tue, 2005/11/15 - 22:26Did you use PHP format? Just use HTML.
--
Khalid Baheyeldin
bomarmonk (not verified)
I-frame in drupal node
Tue, 2005/12/27 - 16:56I'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.
Khalid
Contact me
Wed, 2005/12/28 - 12:12Go to the feedback form and copy/paste the code you are trying, and I will look into it, and reply by email.
Anonymous (not verified)
Code Snippet:Wrapping content from another..
Wed, 2006/05/24 - 21:00Can 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...
Khalid
CSS issue
Wed, 2006/05/24 - 21:19Looks like a CSS issue. Try another theme and see if it works or not. If it does, then it an adc specific CSS bug.
bomarmonl (not verified)
Works!
Thu, 2005/12/29 - 13:40Thanks 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!
putri (not verified)
Where do you plug all this in?
Wed, 2005/12/07 - 12:11This is what I need but I have no clue where to input all this code in. New to Drupal.
Thanks!
Khalid
In a node
Wed, 2005/12/07 - 13:15Create a node, set the input format to PHP code, and paste the code in it.
tallship (not verified)
I created a node (page) and don't see some of the options...
Wed, 2010/07/14 - 04:22I 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 :)
Pages