View Full Version : Dynamically 'Grabbing' Content
GhettoT
10-05-2007, 08:07 AM
I was just wondering, how exactly do you grab content from another site?
ie.
A sports page (website A) has tables setup with stats on teams.
My page (website B) will have empty tables setup.
How do I grab the info from site A and put it into site B? I would like to use purely PHP... I know it is possible, but I can not remember how, nor can I find a tutorial on the subject.
Any help would be greatly appreciated!
jc_gmk
10-05-2007, 08:24 AM
If site A has it's information stored in a database then it is easy with php,
if it's just a static page then I don't know if it's possible, probably not.
You could maybe use an iframe to include the whole page but i doubt you can extract info from table cells directly.
GhettoT
10-05-2007, 09:41 PM
The site uses a database, but I don't have access to it directly...(ie. login information). How were you implying I go about doing this?
djr33
10-05-2007, 09:51 PM
You can get the content of a page using various functions, probably file_get_contents().
Then parse that string as you want.
You can use a marker to find a certain item.
For example, substr($html,strpos($html,'<username>')) would return the html from the page starting at the location of the "username" tag (example; obviously invalid).
1. Code is needed to determine how it will split this. Using substr(), str_replace(), strpos() and other functions would work, or you could learn regex (regular expressions) which are basically a way to use complex wildcards (like * in some search engines) to find, for example the text between 'a' and 'b', etc. They're harder, but more efficient.
2. Specifically, though, you will need to find exactly what determines the data you want. Is it always after a certain tag [ex: '<b>']? Is it after a certain instance of a certain tag [ex: the <b> tag after the text 'names']? Something more complex [the b tag after the word names if the page has names, otherwise it's after the third <p> tag, or it's the title of the page... etc]?
Or you could use an iframe.
Or you could ask permission to the data and find out how to connect. That's the best option. Using data without permission is illegal and there's no way around that. An iframe is a very gray area, leaning toward ok, but actually taking data and claiming it as your own is not; crediting them when doing so is more complex, but still is their right to refuse your use.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.