chriz
chriz

Reputation: 1345

How to find length of element in simple_html_dom

i am using simple_html_dom for for render html in php. In one case i have to check the availability of one particular division. i used following code but but when ever i am using if(isset($GroupHtmlDom->find('#groupFooter'))) condition in my code it crashing my wamp server(see the picture), i dont know y.. following is the exact code i'm using.

 foreach($htmlDom->find('#divGroupSection') as $div{
    $GroupHtmlDom = new simple_html_dom();
    $GroupHtmlDom = str_get_html($div);
    if(isset($GroupHtmlDom->find('#groupFooter')))
        $groupFooter = $GroupHtmlDom->find('#groupFooter')[0]->innertext;
    else
        $groupFooter = '';
    }

how to use jquery length here? $GroupHtmlDom->find('#groupFooter').length is it correct? or instead of isset() is there any other way?
enter image description here

Upvotes: 1

Views: 397

Answers (2)

pguardiario
pguardiario

Reputation: 55002

You would think so, but instead you want count:

echo count($GroupHtmlDom->find('#groupFooter'));

Upvotes: 1

Pedro Lobito
Pedro Lobito

Reputation: 99041

You can use the php function strlen

i.e.:

if(isset($GroupHtmlDom->find('#groupFooter'))){
  $groupFooter = $GroupHtmlDom->find('#groupFooter')[0]->innertext; 
   echo strlen($groupFooter);
}else{
  $groupFooter = ''; 
}

strlen

Returns the length of the given string.

Upvotes: 1

Related Questions