简体   繁体   中英

PHP - Find Nth Occurrence of a DIV

At the moment I have the following

$elem = $reading->find('div[class=time-default]', 0);
$elem = str_replace("<div class=\"time-default\">","",$elem);
$elem = str_replace("</div>","",$elem);

This code looks for <div class="time-default"></div> and does various replaces on it. My question is, if $reading contains multiple DIVs with this class, how can I target the 1st, 2nd, 3rd, Nth one?

I am using this in conjunction with http://simplehtmldom.sourceforge.net/ if that helps

Thanks

find的第二个参数是find的div数组的索引:

$elem = $reading->find('div[class=time-default]', $index);//targets $index_th div

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM