(time()-$CACHE_TTL))) { return file_get_contents($file); } else { $stream = fopen($url,'r'); file_put_contents($file, $stream, LOCK_EX); fclose($stream); } echo file_get_contents($file); } function extract_src($js) { $SRC_LEN = strlen("src=");; $result = array(); //handling of " ' or nothing; $pos = strpos($js, "src="); if ($pos === false) { print("error: HTML tags not valid"); } else { $result[0] = substr($js, 0, $pos); $postSrc = trim(substr($js,$pos)); if ($postSrc[$SRC_LEN] == "'" || $postSrc[$SRC_LEN] == '"') { $postPostSrc = substr($postSrc, $SRC_LEN + 1); $endQuote = strpos($postPostSrc, $postSrc[$SRC_LEN]); $result[1] = substr($postPostSrc, 0, $endQuote); //handling of closing / $endTag = strpos($postPostSrc, ">"); $result[2] = substr($postPostSrc, $endQuote + 1, $endTag - $endQuote); $close = strrpos($result[2], "/"); if (!($close === false)) { $oldResult = $result[2]; $result[2] = substr($oldResult, 0, $close) . substr($oldResult, $close + 1); } return $result; } else { print("error: HTML tags not valid"); } } } function accelerate($js) { //$tag is a table with $tag[0] => everything presrc 1: src src 2=> post src and no closing / $tag = extract_src($js); print $tag[0].$tag[2]; print cache($tag[1]); print ""; } ?>