Forum Moderators: coopster

Message Too Old, No Replies

Getting content from other page

         

eK3eKyToPa

11:28 am on Jul 11, 2008 (gmt 0)

10+ Year Member



I want to display on my page a part of the source code from another page that isn't on the same server.
For example if my variable is "Blue%20Widgets"
to get a part from the source of page:
http://www.example.com/?search=Blue%20Widgets
I need only the:
displayId: 30587, slot: 8
part to be displayed

If possible give some examples

[edited by: eK3eKyToPa at 11:30 am (utc) on July 11, 2008]

[edited by: coopster at 12:28 pm (utc) on July 11, 2008]
[edit reason] generalized domain and keywords [/edit]

eelixduppy

5:00 pm on Jul 11, 2008 (gmt 0)



You can grab the source from that page using file_get_contents [php.net]() and then depending on the formatting you are going to have to use a mixture of string functions to grab the data that you want. The most likely youu'll be using, however, is regular expressions [php.net]. Take a look and see what you can do.

eK3eKyToPa

5:49 pm on Jul 11, 2008 (gmt 0)

10+ Year Member



I use this

if ( $e1 !="_" && $e1 != "") {
$data=file_get_contents("http://www.localhost.com/?search=PAGE",FALSE,NULL,0,7000);
list($nachalensors, $displayIdplus) = explode("displayId:", $data);
list($displayId, $slotplus) = explode(", slot: ", $displayIdplus);
list($slot, $krai) = explode('})">', $slotplus);

echo $slot . ", " . $displayId . ", ";

}
And this works, but maybe will be slow
AND I cant set the source site as a variable
this dont works:

$e1 = "PAGE";
$search = "http://www.localhost.com/?search=" . $e1;
$data=file_get_contents( $search ,FALSE,NULL,0,7000);

HOW to do it ?

[edited by: eK3eKyToPa at 5:50 pm (utc) on July 11, 2008]

eelixduppy

7:08 pm on Jul 11, 2008 (gmt 0)



In order for me to help you extract the data from the page, can you give me an example of the format the data is in? I can get a basic understanding by how you are extracting it, but for me to truly help you I need an exact look at how it's being displayed.

As for your code not working with the variable 'search' terms, there is only one problem that I see, which, given the example you have shown above, isn't a problem for that specific case. The only thing you should do it urlencode the search string like this:


$search = 'http://www.example.com/?search=' . [url=http://www.php.net/urlencode]urlencode[/url]($e1);

other than that it looks fine. Check for any errors in your error log to see if anything comes up? It should be working, however.