[英]How to find length of element in simple_html_dom
我正在使用simple_html_dom
在php中渲染HTML。 在一種情況下,我必須檢查一個特定部門的可用性。 我使用了以下代碼,但是每當我在代碼中使用if(isset($GroupHtmlDom->find('#groupFooter')))
條件時,它都會崩潰我的wamp服務器(參見圖片),我不知道。是我正在使用的確切代碼。
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 = '';
}
如何在這里使用jquery length
? $GroupHtmlDom->find('#groupFooter').length
是否正確? 或代替isset()
還有其他方法嗎?
您可以使用php函數strlen
即:
if(isset($GroupHtmlDom->find('#groupFooter'))){
$groupFooter = $GroupHtmlDom->find('#groupFooter')[0]->innertext;
echo strlen($groupFooter);
}else{
$groupFooter = '';
}
strlen的
返回給定字符串的長度。
您可能會這樣想,但您想算一下:
echo count($GroupHtmlDom->find('#groupFooter'));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.