Consolidate RapidWeaver style sheets

Send Snippet To: Save this snippet to Code Collector Pro -- view all seydoggy's snippets
language: PHP
license: Other

Code for Snippet:

                
<?PHP 
//get contents of buffer and discard
$out = ob_get_clean(); 
 
//split by newline
$arry_lines = split("[\n|\r]", $out);
 
//initialize vars
$newout="";
$beginStyleTag='<style type="text/css" media="all">';
$endStyleTag='</style>';
$pattern='/(<link\b.+href=")(?!http)([^"]*)(".*>)/';
 
//loop through each line of buffer
foreach ($arry_lines as &$value) {
   if (preg_match($pattern, $value)) {
        //found a css link
       //get the path to the css and then store the content of the css in var
        $filepath='./'.trim(str_replace('" />','',preg_replace($pattern,'$2$3$4', $value)));
        $file = file_get_contents($filepath, FILE_USE_INCLUDE_PATH);
        //inject style tags and css content into buffer
        $newout=$newout.$beginStyleTag.minify($file).$endStyleTag;
    }
    else {
        //not a link, so just add to buffer
        $newout=$newout.$value;
    }
}
echo($newout); 
?>
comments powered by Disqus

Info

Link to this snippet:


Download to Code Collector

To use the direct link to your snippet on CodeCollector.net either copy the html from the above section or drag the Download to Code Collector to where you would like to use it.

More Info:

Times Viewed: 838
Date Added: 2010-05-03 03:36:49
Last Modified: 0000-00-00 00:00:00

Web Analytics