PHP Proxy HTML контента

<?php
//ini_set (\'error_reporting\', E_ALL);
//ini_set (\'display_errors\', \'on\');

function CachedFileImport($cachefilename, $filename, $cachelivetime, $newbaseurl)
{
//cached newspaper import
$cachedtime = filemtime($cachefilename);
//update cache every minute
// echo $cachedtime.\'-\'.time();
$isUpdateCache = time()- $cachedtime > $cachelivetime;
$text = "";
if(!$isUpdateCache){
$text = ImportFile($cachefilename);
}

//update cache if time out excited or cached file read failed
if($text === false || $text == \'\')
{
$text = ImportFile($filename);
//save cached file
if($text !== false){
//Take text bitween tags
$text = CutPageContent($text, \'\');
//Raplece add base url to relative links, images, background
$text = ReplaceLinkBases($text, $newbaseurl);
//convert encoding
$text = iconv(\'utf-8\',\'windows-1251\',$text);
SaveFile($cachefilename, $text);
}
}
//show news start page
return $text;
}

function ImportFile($filename)
{
$text = \'\';
$handle = @fopen($filename, "rb");
if(!$handle)
return false;

while (!feof($handle)) {
$text .= fread($handle, 8192);
}
fclose($handle);
return $text;
}

function SaveFile($filename, $text)
{
$outf= @fopen($filename,"w+b");
if(!$outf)
return false;
fwrite($outf, $text);
fclose($outf);
return true;
}

function ReplaceLinkBases($text, $newbaseurl)
{
//replace href links
$text = preg_replace(\'/(<.*?)\s(href|src|background)=\s*[\\'"]?(?!\s*[\\'"]?http\:\/\/)(.*?)["\\' >]/\',\'\\1 \\2="\'.$newbaseurl.\'/\\3"\', $text);
return $text;
}

function CutPageContent($text, $starttag, $endtag)
{
//cut HTML content
$pos_start = strpos($text, $starttag);
if($pos_start != -1)
{
$closeTag = $endtag;
$pos_end = strrpos($text, $closeTag) + strlen($closeTag);
//extract text bitween start and end tag including tags itself
$text = substr($text, $pos_start, $pos_end - $pos_start);
}
return $text;
}
?>

Из существующих библиотек наиболее проста в использовании и работоспособна оказалась PHProxy