1<?php 2// $Header: /cvsroot/html2ps/xhtml.style.inc.php,v 1.7 2007/03/15 18:37:36 Konstantin Exp $ 3 4function process_style(&$html) { 5 $styles = array(); 6 7 if (preg_match('#^(.*)(<style[^>]*>)(.*?)(</style>)(.*)$#is', $html, $matches)) { 8 $styles = array_merge(array($matches[2].process_style_content($matches[3]).$matches[4]), 9 process_style($matches[5])); 10 $html = $matches[1].$matches[5]; 11 }; 12 13 return $styles; 14} 15 16function process_style_content($html) { 17 // Remove CDATA comment bounds inside the <style>...</style> 18 $html = preg_replace("#<!\[CDATA\[#","",$html); 19 $html = preg_replace("#\]\]>#is","",$html); 20 21 // Remove HTML comment bounds inside the <style>...</style> 22 $html = preg_replace("#<!--#is","",$html); 23 $html = preg_replace("#-->#is","",$html); 24 25 // Remove CSS comments 26 $html = preg_replace("#/\*.*?\*/#is","",$html); 27 28 // Force CDATA comment 29 $html = '<![CDATA['.$html.']]>'; 30 31 return $html; 32} 33 34function insert_styles($html, $styles) { 35 // This function is called after HTML code has been fixed; thus, 36 // HEAD closing tag should be present 37 38 $html = preg_replace('#</head>#', join("\n", $styles)."\n</head>", $html); 39 return $html; 40} 41 42?>