SimpleHtmldom を使用して、 class を持つ最初の要素のコンテンツを抽出できますdescription
。
$html = str_get_html($html);
$html->find('.description', 0)
ただし、このクラスが存在しない場合、PHP はエラーをスローします。
Trying to get property of non-object
私は試した
if(!isset($html->find('.description', 0))) {
echo 'not set';
}
と
if(!empty($html->find('.description', 0))) {
echo 'not set';
}
しかし、両方ともエラーが発生します
Can't use method return value in write context
要素が存在するかどうかを確認する適切な方法は何ですか?