One of the dangers of using newer PHP functions is that sometimes you’ll end up with people who are stuck on a shared host using an older version of PHP. In this case it’s helpful to have some backwards compatible functions. The category backwards compatability will deal with these situations.

file_get_contents has only been available in PHP since 4.3.0. Here is how to make it backwards compatible to version 3.xx of PHP by using file and implode:

<?php
// PHP 4.3.0 or later
$page_source = file_get_contents(“http://www.yourdomain.com/yourpage.html”);

// pre 4.3.0
$page_source = implode(, file(“http://www.yourdomain.com/yourpage.html”));
?>

Now let’s say you wanted to make your own file_get_contents function for pre 4.3.0? Here’s what you would do:

<?php
// only use this in pre 4.3.0 PHP where file_get_contents is not available
function file_get_contents($in) {
  return  implode(, file($in));
}
$page_source = file_get_contents(‘http://www.yourdomain.com/yourpage.html’);
?>