And testing with random whitespace;<br><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote"><span style="font-family: courier new,monospace;">$text = '
<span style="background-color: rgb(255, 255, 204);"><span style="background-color: rgb(255, 255, 0);"> style=" font-style : italic ; font-weight : bold ; " </span>'</span>;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">$regex = "\s*([a-z][a-z0-9\-]*)\s*:\s*([a-z][a-z0-9\-]*)\s*;";</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
if (preg_match_all('/'. $regex .'/i', $text, $matches, PREG_SET_ORDER)) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> print_r($matches);</span>
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">$style = array();
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">foreach ($matches as $match) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
$style[$match[1]] = $match[2];</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
print_r($style);</span></blockquote><div><br>works<br></div><br><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote"><span style="font-family: courier new,monospace;">
Array</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">(</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> [0] => Array
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> [0] => font-style : italic ;
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> [1] => font-style</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
[2] => italic</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> )</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> [1] => Array</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> [0] => font-weight : bold ;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> [1] => font-weight
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> [2] => bold</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
)</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
Array</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">(</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> [font-style] => italic
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> [font-weight] => bold</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
)</span></blockquote><div><br>Testing with commonly practiced and supported syntactical errors and irregularities;<br><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">
<span style="font-family: courier new,monospace;">$text = '<span style="background-color: rgb(255, 255, 0);">style=font-style:italic;font-weight:bold</span>';</span><br></blockquote>doesn't all work<br></div><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">
<span style="font-family: courier new,monospace;">Array</span><br><span style="font-family: courier new,monospace;">(</span><br><span style="font-family: courier new,monospace;"> [0] => Array</span><br><span style="font-family: courier new,monospace;">
(</span><br><span style="font-family: courier new,monospace;"> [0] => font-style:italic;</span><br><span style="font-family: courier new,monospace;"> [1] => font-style</span><br><span style="font-family: courier new,monospace;">
[2] => italic</span><br><span style="font-family: courier new,monospace;"> )</span><br><span style="font-family: courier new,monospace;">)</span><br><span style="font-family: courier new,monospace;">
Array</span><br><span style="font-family: courier new,monospace;">(</span><br><span style="font-family: courier new,monospace;"> [font-style] => italic</span><br><span style="font-family: courier new,monospace;">)</span>
</blockquote><div><br>It also doesn't work for non-textual properties, and property names starting with '-' exclude the '-';<br><blockquote><span style="font-family: courier new,monospace;">
$text = 'style=border-width: 0 2em 10px 0; border-left: 1px solid #000; -moz-border-radius: foo;';</span><br style="font-family: courier new,monospace;"></blockquote><span>outputs<br></span><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">
<span><span style="font-family: courier new,monospace;">Array</span></span><br style="font-family: courier new,monospace;"><span><span style="font-family: courier new,monospace;">(</span></span><br style="font-family: courier new,monospace;">
<span><span style="font-family: courier new,monospace;"> [0] => Array</span></span><br style="font-family: courier new,monospace;"><span><span style="font-family: courier new,monospace;"> (</span></span><br style="font-family: courier new,monospace;">
<span><span style="font-family: courier new,monospace;"> [0] => moz-border-radius: foo;</span></span><br style="font-family: courier new,monospace;"><span><span style="font-family: courier new,monospace;"> [1] => moz-border-radius
</span></span><br style="font-family: courier new,monospace;"><span><span style="font-family: courier new,monospace;"> [2] => foo</span></span><br style="font-family: courier new,monospace;"><span><span style="font-family: courier new,monospace;">
)</span></span><br style="font-family: courier new,monospace;"><span></span><br style="font-family: courier new,monospace;"><span><span style="font-family: courier new,monospace;">)</span></span><br style="font-family: courier new,monospace;">
<span><span style="font-family: courier new,monospace;">Array</span></span><br style="font-family: courier new,monospace;"><span><span style="font-family: courier new,monospace;">(</span></span><br style="font-family: courier new,monospace;">
<span><span style="font-family: courier new,monospace;"> [moz-border-radius] => foo</span></span><br style="font-family: courier new,monospace;"><span><span style="font-family: courier new,monospace;">)</span></span>
<br style="font-family: courier new,monospace;"><span></span></blockquote></div><span>This regex deals with those issues (but not the missing trailing semicolon ';' <span style="background-color: rgb(255, 255, 255); font-family: courier new,monospace;">
$regex = "<span style="background-color: rgb(255, 255, 0);">\s*([a-z\-][a-z0-9\-]*)\s*:\s*([^;]*)\s*;</span>";<br><br></span></span><span>I'm not sure what the best way to deal with that is given the context. Perhaps something like
</span><span><span style="background-color: rgb(255, 255, 255); font-family: courier new,monospace;"><br></span></span><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">
<span><span style="background-color: rgb(255, 255, 255); font-family: courier new,monospace;">$text = 'font-style:italic;font-weight:bold';</span></span><br><span><span style="background-color: rgb(255, 255, 255); font-family: courier new,monospace;">
$regex = "\s*([a-z\-][a-z0-9\-]*)\s*:\s*([^;]*)\s*";</span></span><br><span><span style="background-color: rgb(255, 255, 255); font-family: courier new,monospace;">$styles = <span style="background-color: rgb(255, 255, 51);">
explode(';', $text)</span>;</span></span><br><span><span style="background-color: rgb(255, 255, 255); font-family: courier new,monospace;">$all_matches = array();</span></span><br><span><span style="background-color: rgb(255, 255, 255); font-family: courier new,monospace;">
<span style="background-color: rgb(255, 255, 51);">foreach($styles as $style)</span> {</span></span><br><span><span style="background-color: rgb(255, 255, 255); font-family: courier new,monospace;"> if (preg_match('/'. $regex .'/i', $style, $matches)) {
</span></span><br><span><span style="background-color: rgb(255, 255, 255); font-family: courier new,monospace;"> print_r($matches);</span></span><br><span><span style="background-color: rgb(255, 255, 255); font-family: courier new,monospace;">
$all_matches[] = $matches;</span></span><br><span><span style="background-color: rgb(255, 255, 255); font-family: courier new,monospace;"> }</span></span><br><span><span style="background-color: rgb(255, 255, 255); font-family: courier new,monospace;">
}</span></span><br><span><span style="background-color: rgb(255, 255, 255); font-family: courier new,monospace;">$style = array();</span></span><br><span><span style="background-color: rgb(255, 255, 255); font-family: courier new,monospace;">
foreach ($all_matches as $match) {</span></span><br><span><span style="background-color: rgb(255, 255, 255); font-family: courier new,monospace;"> $style[$match[1]] = $match[2];</span></span><br><span><span style="background-color: rgb(255, 255, 255); font-family: courier new,monospace;">
}</span></span><br><span><span style="background-color: rgb(255, 255, 255); font-family: courier new,monospace;">print_r($style);</span></span></blockquote><div><br>Bevan/ <br></div><br>