本文整理汇总了PHP中TCPDF_STATIC::extractCSSproperties方法的典型用法代码示例。如果您正苦于以下问题:PHP TCPDF_STATIC::extractCSSproperties方法的具体用法?PHP TCPDF_STATIC::extractCSSproperties怎么用?PHP TCPDF_STATIC::extractCSSproperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TCPDF_STATIC
的用法示例。
在下文中一共展示了TCPDF_STATIC::extractCSSproperties方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getHtmlDomArray
/**
* Returns the HTML DOM array.
* @param $html (string) html code
* @return array
* @protected
* @since 3.2.000 (2008-06-20)
*/
protected function getHtmlDomArray($html)
{
// array of CSS styles ( selector => properties).
$css = array();
// get CSS array defined at previous call
$matches = array();
if (preg_match_all('/<cssarray>([^\\<]*)<\\/cssarray>/isU', $html, $matches) > 0) {
if (isset($matches[1][0])) {
$css = array_merge($css, unserialize($this->unhtmlentities($matches[1][0])));
}
$html = preg_replace('/<cssarray>(.*?)<\\/cssarray>/isU', '', $html);
}
// extract external CSS files
$matches = array();
if (preg_match_all('/<link([^\\>]*)>/isU', $html, $matches) > 0) {
foreach ($matches[1] as $key => $link) {
$type = array();
if (preg_match('/type[\\s]*=[\\s]*"text\\/css"/', $link, $type)) {
$type = array();
preg_match('/media[\\s]*=[\\s]*"([^"]*)"/', $link, $type);
// get 'all' and 'print' media, other media types are discarded
// (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
if (empty($type) or isset($type[1]) and ($type[1] == 'all' or $type[1] == 'print')) {
$type = array();
if (preg_match('/href[\\s]*=[\\s]*"([^"]*)"/', $link, $type) > 0) {
// read CSS data file
$cssdata = TCPDF_STATIC::fileGetContents(trim($type[1]));
if ($cssdata !== FALSE and strlen($cssdata) > 0) {
$css = array_merge($css, TCPDF_STATIC::extractCSSproperties($cssdata));
}
}
}
}
}
}
// extract style tags
$matches = array();
if (preg_match_all('/<style([^\\>]*)>([^\\<]*)<\\/style>/isU', $html, $matches) > 0) {
foreach ($matches[1] as $key => $media) {
$type = array();
preg_match('/media[\\s]*=[\\s]*"([^"]*)"/', $media, $type);
// get 'all' and 'print' media, other media types are discarded
// (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
if (empty($type) or isset($type[1]) and ($type[1] == 'all' or $type[1] == 'print')) {
$cssdata = $matches[2][$key];
$css = array_merge($css, TCPDF_STATIC::extractCSSproperties($cssdata));
}
}
}
// create a special tag to contain the CSS array (used for table content)
$csstagarray = '<cssarray>' . htmlentities(serialize($css)) . '</cssarray>';
// remove head and style blocks
$html = preg_replace('/<head([^\\>]*)>(.*?)<\\/head>/siU', '', $html);
$html = preg_replace('/<style([^\\>]*)>([^\\<]*)<\\/style>/isU', '', $html);
// define block tags
$blocktags = array('blockquote', 'br', 'dd', 'dl', 'div', 'dt', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'li', 'ol', 'p', 'pre', 'ul', 'tcpdf', 'table', 'tr', 'td');
// define self-closing tags
$selfclosingtags = array('area', 'base', 'basefont', 'br', 'hr', 'input', 'img', 'link', 'meta');
// remove all unsupported tags (the line below lists all supported tags)
$html = strip_tags($html, '<marker/><a><b><blockquote><body><br><br/><dd><del><div><dl><dt><em><font><form><h1><h2><h3><h4><h5><h6><hr><hr/><i><img><input><label><li><ol><option><p><pre><s><select><small><span><strike><strong><sub><sup><table><tablehead><tcpdf><td><textarea><th><thead><tr><tt><u><ul>');
//replace some blank characters
$html = preg_replace('/<pre/', '<xre', $html);
// preserve pre tag
$html = preg_replace('/<(table|tr|td|th|tcpdf|blockquote|dd|div|dl|dt|form|h1|h2|h3|h4|h5|h6|br|hr|li|ol|ul|p)([^\\>]*)>[\\n\\r\\t]+/', '<\\1\\2>', $html);
$html = preg_replace('@(\\r\\n|\\r)@', "\n", $html);
$repTable = array("\t" => ' ', "" => ' ', "\v" => ' ', "\\" => "\\\\");
$html = strtr($html, $repTable);
$offset = 0;
while ($offset < strlen($html) and ($pos = strpos($html, '</pre>', $offset)) !== false) {
$html_a = substr($html, 0, $offset);
$html_b = substr($html, $offset, $pos - $offset + 6);
while (preg_match("'<xre([^\\>]*)>(.*?)\n(.*?)</pre>'si", $html_b)) {
// preserve newlines on <pre> tag
$html_b = preg_replace("'<xre([^\\>]*)>(.*?)\n(.*?)</pre>'si", "<xre\\1>\\2<br />\\3</pre>", $html_b);
}
while (preg_match("'<xre([^\\>]*)>(.*?)" . $this->re_space['p'] . "(.*?)</pre>'" . $this->re_space['m'], $html_b)) {
// preserve spaces on <pre> tag
$html_b = preg_replace("'<xre([^\\>]*)>(.*?)" . $this->re_space['p'] . "(.*?)</pre>'" . $this->re_space['m'], "<xre\\1>\\2 \\3</pre>", $html_b);
}
$html = $html_a . $html_b . substr($html, $pos + 6);
$offset = strlen($html_a . $html_b);
}
$offset = 0;
while ($offset < strlen($html) and ($pos = strpos($html, '</textarea>', $offset)) !== false) {
$html_a = substr($html, 0, $offset);
$html_b = substr($html, $offset, $pos - $offset + 11);
while (preg_match("'<textarea([^\\>]*)>(.*?)\n(.*?)</textarea>'si", $html_b)) {
// preserve newlines on <textarea> tag
$html_b = preg_replace("'<textarea([^\\>]*)>(.*?)\n(.*?)</textarea>'si", "<textarea\\1>\\2<TBR>\\3</textarea>", $html_b);
$html_b = preg_replace("'<textarea([^\\>]*)>(.*?)[\"](.*?)</textarea>'si", "<textarea\\1>\\2''\\3</textarea>", $html_b);
}
$html = $html_a . $html_b . substr($html, $pos + 11);
$offset = strlen($html_a . $html_b);
//.........这里部分代码省略.........