Just some regular functions to put at the start of a webpage..\\
<code>
<?php 
function extract_unit($string, $start, $end, $offset) {
$pos = stripos($string, $start, $offset) + strlen($start);
$second_pos = stripos($string, $end, $offset)- $pos;
if ($second_pos > 0) { return substr($string, $pos, $second_pos); }
else { return ''; }
}

function curldata($surl,$sfile,$stime) {
// download a webpage
 if (!file_exists($sfile) or (time() - filemtime($sfile) >= $stime)){
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL,$surl);
  curl_setopt($ch, CURLOPT_HEADER, 1); 
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  return curl_exec($ch);
 } else return file_get_contents($sfile);
}

function getdata($sfile,$surl,$slife) {
/*gets new file if old file is more than 2 hours old */
//slife is caching time, in seconds i.e. 7200 is two hours
if (!file_exists($sfile) or (time() - filemtime($sfile) >= $slife)){
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL,$surl);
 curl_setopt($ch, CURLOPT_HEADER, 1); 
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
 $fp = fopen($sfile, 'w');
 $data = curl_exec($ch);
 fwrite($fp,$data);
 curl_close($ch);
 fclose($fp);
} else $data=file_get_contents($sfile);
return $data;
}

function acronym($string) {
// make an acronym from the string word separated by spaces
return preg_replace('/\b(\w)\w*\W*/', '\1', $string);
}
?>
</code>