Skip to content

Commit

Permalink
fixed: Notice error
Browse files Browse the repository at this point in the history
  • Loading branch information
fim committed Feb 19, 2010
1 parent 8c712ba commit 273033d
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions instyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ function convert($document) {
// Extract the CSS
preg_match('/<style[^>]+>(?<css>[^<]+)<\/style>/s', $document, $matches);

// If no CSS style
if (empty($matches)){
return $document;
}

// Strip out extra newlines and tabs from CSS
$css = preg_replace("/[\n\r\t]+/s", "", $matches['css']);

Expand All @@ -48,12 +53,20 @@ function convert($document) {
// Create a separate array element in styles array for each declaration
$selectors = explode(',', $rule['1']);
foreach($selectors as $selector) {
$styles[trim($selector)] .= trim($rule['2']);
if ($debug) { echo trim($selector) . ' { ' . trim($rule['2']) . ' }<br/>'; }
$selector = trim($selector);
if (!isset($styles[$selector])) {
$styles[$selector] ='';
}
$styles[$selector] .= trim($rule['2']);
if ($debug) { echo $selector . ' { ' . trim($rule['2']) . ' }<br/>'; }
}
} else {
$styles[trim($rule['1'])] .= trim($rule['2']);
if ($debug) { echo trim($rule['1']) . ' { ' . trim($rule['2']) . ' }<br/>'; }
$selector = trim($rule['1']);
if (!isset($styles[$selector])) {
$styles[$selector] = '';
}
$styles[$selector] .= trim($rule['2']);
if ($debug) { echo $selector . ' { ' . trim($rule['2']) . ' }<br/>'; }
}
}

Expand Down

0 comments on commit 273033d

Please sign in to comment.