我想检查一个属性是否存在,如果它不是空的。我使用PHP简单HTML DOM解析器来探索DOM。我试着在属性过滤器选项卡下查看。
作为一个例子,我得到这个:
if ( $html->find('meta[property=og:locale]') && IfNotEmptyCondition )
{
foreach ($html->find('meta[property=og:locale]') as $element) {
echo $element->content;
}
} else {
echo 'Votre site ne propose pas la balise <em>OG:locale</em>';
}
echo '<br>';
在if我不知道如何看如果og:locale属性不是空的
这只是一个有点不同的角度:你可以在continue
:
foreach
内部的空的。$elements = $html->find('meta[property=og:locale]');
foreach ($elements as $element)
{
if ($element->content === '') {
continue;
}
echo $element->content;
}