I need to parse some HTML tags and display the style classes, and have
it partly working, but need some regex / preg_match advise.
If the tag is <td class="red" colspan="1"> I can display "td.red"
If the tag is <td colspan="1" class="red"> my regex doesn't display the
desired "td.red" ... I can't figure out how to skip over colspan="1" if
the class doesn't immediately follow the HTML tag name.
$lines = explode("\n", $html);
foreach($lines as $line){
if(stristr($lin e, '<') && strstr($line, 'class=')){
if(preg_match("/<+([a-z]+) class=\"+([_a-z0-9-]+)\"/", $line,
$matches)){
echo
'<b>'.htmlspeci alchars($matche s[1].'.'.$matches[2]).'</b><br><br>'."\n ";
}
}
}
TIA.
it partly working, but need some regex / preg_match advise.
If the tag is <td class="red" colspan="1"> I can display "td.red"
If the tag is <td colspan="1" class="red"> my regex doesn't display the
desired "td.red" ... I can't figure out how to skip over colspan="1" if
the class doesn't immediately follow the HTML tag name.
$lines = explode("\n", $html);
foreach($lines as $line){
if(stristr($lin e, '<') && strstr($line, 'class=')){
if(preg_match("/<+([a-z]+) class=\"+([_a-z0-9-]+)\"/", $line,
$matches)){
echo
'<b>'.htmlspeci alchars($matche s[1].'.'.$matches[2]).'</b><br><br>'."\n ";
}
}
}
TIA.
Comment