ECMS V3

This page is brought to you by ECMS V3 - Next Generation Web Management (http://www.evaria.com/). When printing this page (http://www.evaria.com/v3/index/article/44/grabbing-remote-content.html),
you must include the entire legal notice at bottom.

51
district-librarian

Grabbing remote content

While I was putting together some code in order to grab today’s comic for my blog from various websites I experimented with several different functions to find the most efficient solution.

5 Published 08.06.2007 - Last edited 08.06.2007 - 3793 views - 0 comments

In the end I ended up using file_get_contents which reads the entire remote file into a string and returns false if file doesn’t exist.

Compared to other functions like file, file_get_contents is by far a lot quicker and more stable/reliable. Grabbing complete web pages takes approximately 1 second on average. This having a cache function with only a few calls per day shouldn’t affect your servers performance at all.

In my coding experiment I needed to grab 17 characters from a page. This was achieved using the following function:

function getCode($source,$open,$close)
{
    $part1 = explode($open,$source);
    $part2 = explode($close,$part1[1]);
    return [0];
}

Then you call the function and assign the value to a variable like this (all in one line):

$remoteFile = substr(getCode(@file_get_contents("source"),
"string before", "string after"), 0, 18);

Feel free to comment or ask for more information about how to set up a caching system and automatically maintain the temporary file (cached) c";


Name:

Email: hidden

Website:

Comment:

Please enter these letters here (Case sensitive) *

While we are updating content in the new site, the original Evaria site can be accessed via this link.

Page generated in 0.047s

evaria.com © 1999-2012 HTML CSS Contact us Back to top