$html='<style> .active { color:#ffffff; background:#0A246A; cursor:default; } #template { text-align:center; width:145px; border:1px solid #aaa; float:left; margin:5px; } #template #info { height:100px; width:98%; padding: 2px; } #template h6 { margin:0; padding:0; border:0; } #template #use { width:100%; background:#aaa; color:#fff; display:block; font-weight:bold; text-decoration:none; cursor:pointer; } #template #use input { height:10px; width:10px; } </style> <script> function change_rss(t){ f = document.getElementById("rss"); if(t == "html"){ f.style.display = "none"; }else{ f.style.display = "inline"; } } </script> PHP: Hi I need to extract only css class not css ID from this string. For example, from above string, I need a expression so that it gives output array('.active') PHP: becoz .active is the only css class. Pls help
Here is a starting point (I suck bad at regex): preg_match_all('~\.(.*?)\s~',$html,$matches); echo '<pre>'; print_r($matches[0]); echo '</pre>'; PHP: Put that under you HTML variable. Unfortunately it picks up anything in the script element too, so you'll need some more help, but its still a start.
preg_match_all('~[\s\}>](\.[\w-]+)\s*\{~', $html, $matches); echo '<pre>', print_r($matches[1], true), '</pre>'; PHP: ... this should be pretty precise.