SimpleHtmldom can be used to extract the contents of the first element with class description
.
$html = str_get_html($html);
$html->find('.description', 0)
However if this class does not exist, PHP will throw an error
Trying to get property of non-object
I tried
if(!isset($html->find('.description', 0))) {
echo 'not set';
}
and
if(!empty($html->find('.description', 0))) {
echo 'not set';
}
but both gives the error
Can't use method return value in write context
What is the proper way to check if the element exist?
empty
cannot operat directly on the value.$html->find()
returns an empty array if element was not found. So the solution offered by Death should be valid. – Romanfleuve