Forum Moderators: coopster

Message Too Old, No Replies

using PHP to get content from another domain?

         

GaryS622

7:45 pm on Sep 30, 2004 (gmt 0)

10+ Year Member



This may be a pretty vague question from a technical point of view, but I'm trying to keep an open mind about the best approach...

I'm designing a website where the company has a couple of catalogs which are provided by external vendors. For example,

www.example.com

provides a place for customers to browse for blank goods. It's not really an e-commerce site, but it's designed to be generic. I want it to appear within the menu/layout of the main site.

I have a couple of "low-tech" options - place it in a frameset, maybe with a banner up top just to remind the user where they came from and allow easy navigation back to the rest of the site. But this doesn't allow me to keep much of the "look and feel" of the rest of the site, which is built around a .css style sheet with a 3-column layout. I'd like to keep this content in the center column.

Or of course I could just spawn a new browser window and have this content be separate from the rest of the site. But of course that's even worse in terms of interconnection with the rest of the site.

I've seen a site that grabbed another site's content and kept it inside a section of the main site's page, but I can't remember where I saw it and I don't know if they were doing it with php, Java, or what.

I figured out how to put the page inside the main page with a php include, but of course whenever you click on a link inside this area, you just end up going wherever the link sent you and the content from the other columns is not preserved.

[edited by: coopster at 8:40 pm (utc) on Sep. 30, 2004]
[edit reason] generalized url per TOS [webmasterworld.com] [/edit]

mincklerstraat

7:53 am on Oct 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Normally getting content from another domain will either involve screenscraping, or a special 'feed' the other domain generates which allows you to put their content on your page - either in js or xml. Both of these are a bit advanced, I'd guess, for your current level of php skills unless you really want to go all-out and learn a bit more php. Probably at the moment your best choice would be to go with the low-tech frames alternative.

To do screenscraping, you'll want to study file_get_contents() and str_replace(); if str_replace doesn't do it, then study preg_replace() and preg_replace_all(). These last two are a bit more complicated but very powerful when manipulating stings.

GaryS622

2:13 pm on Oct 1, 2004 (gmt 0)

10+ Year Member



Okay - I've heard of screen scraping, but that's in the same sense that I've heard of "brain surgery." Yep, probably more than I want to bite off yet, so probably going with frames. Frames - how 90's, yet some applications they're hard to do without.

And I will ask the vendors in question about an XML feed, as I'm on a little more familiar ground there, but due to the nature of the sites, I may be out of luck.

Note to the mods - sorry, didn't think about my URL. No plugging of my wares intended.

coopster

2:35 pm on Oct 1, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Forgiven ;)

Welcome to WebmasterWorld, GaryS622!