here is a method to select elements that fits all those criteria, at once. It returns an array of the elements that fit in all the criteria, or an array of zero elements.
It accepts either an array of elements or a single element.
The criteria needs to be delimited by commas, and it will returned elements that fit in all those criteria.
Example usage
$dom = new simple_html_dom();
$dom->load($Email);
//This would select elements with only those selected criteria
//Then what is returned is an array, and then we select further elements that
//are em
$selection = GetSelectionMultiple($dom, "font, .ff2, .fs16, .fc1, .fwn, .gf");
$em = GetSelectionMultiple($selection, "em");
function GetSelectionMultiple($single_element_or_array, $criteria, $delimiter=",")
{
$array_split = explode($delimiter, $criteria);
$remove_emptyones = [];
for($index=0; $index<count($array_split); $index++)
{
$sel = trim($array_split[$index]);
if(strlen($sel) > 0)
{
$remove_emptyones[] = $sel;
}
}
$array_split = $remove_emptyones;
//Elements which will be returned
$array_element = [];
$dom_array = [];
if(is_array($single_element_or_array) == false)
{
$dom_array[] = $single_element_or_array;
}
else
{
foreach($single_element_or_array as $iterate)
{
$dom_array[] = $iterate;
}
}
for( $domindex=0; $domindex<count($dom_array); $domindex++ )
{
$current_find = null;
$dom = $dom_array[$domindex];
for($index=0; $index<count($array_split); $index++)
{
$use = trim($array_split[$index]);
if(strlen($use) == 0)
continue;
if($index == 0)
{
$current_find = $dom->find($use);
foreach($current_find as $element)
{
$array_element[] = $element;
}
}
else
{
//Each array element find things now and add them or remove them
for($check=0; $check<count($array_element); $check++ )
{
$parent = $array_element[$check]->parent;
if($parent == null || $parent == false)
{
continue;
}
$current_find = $parent->find($use);
if($current_find != null && $current_find && count($current_find) > 0)
{
foreach($current_find as $element)
{
$matches = false;
for($c=0; $c<count($array_element); $c++)
{
if($array_element[$c] === $element)
{
$matches =true;
break;
}
}
if($matches == false)
{
$array_element[$check] = null;
}
}
}
else
{
$array_element[$check] = null;
}
}
//Remove the null elements
$newarray = [];
for($check=0; $check<count($array_element); $check++ )
{
$current_find = $array_element[$check];
if($current_find != null)
{
$newarray[] = $current_find;
}
}
$array_element = $newarray;
}
}
}
return $array_element;
}