codeinphp Posted August 5, 2015 Share Posted August 5, 2015 (edited) Trying to parse some html but having trouble getting it into "groups". I am able to parse the html below into single elements with the following code. The html shown is only one group of information being parsed and is grouped by based on the data-channelid. Following this group starts a new section with a different data-channelid followed by same classes just with different values and iformation. How can it be parsed to have a result groupled by the data-channelid? As I show below, I can get each individual item by can't seem to put them together like: CHANNEL="1" SHOW="SHOW1" TIME="WHATEVERTIME" DESC="BLABLA" CHANNEL="1" SHOW="SHOW2" TIME="WHATEVERTIME" DESC="BLABLA" CHANNEL="1" SHOW="SHOW3" TIME="WHATEVERTIME" DESC="BLABLA" then once all elements related to CHANNEL="1", parse the next group based on its channelid. foreach ($aclasses as $aclass){ $cid[]=$aclass->getAttribute('data-channelid'); } foreach ($progcols as $progcol){ foreach ($names as $name){ $show[]=$name->nodeValue; } foreach ($times as $time){ $ptime[]=$time->nodeValue; } foreach ($descs as $desc){ $pdesc[]=$desc->nodeValue; } } //PROGRAMCOLS for($i=0; $i<count($show); $i++){ echo "CHANNEL. . . . . ".$cid[$i]."<br>"; echo "SHOW. . . . . ".$show[$i]."<br>"; echo "TIME. . . . . ".$ptime[$i]."<br>"; echo "DESC. . . . . ".$pdesc[$i]."<br>"; } <div class="col th"> <a class="channel_sched_link" href="javascript:void(0)" title="TITLE1" data-channelid="1"> <img src="/XXXXX" width="30" height="20" alt="AA" />AA </a> </div> <div class="prog_cols"> <div class="col ts ts_1 prog_1045493 ps_0" data-catid="" > <span class="name">SHOW1</span> <div class="time">August 5, 2015, 11:00 am - 1:00 pm</div> <div class="desc">Information here.<br/> </div> </div> <div class="col ts ts_2 prog_1045494 ps_1" data-catid="" > <span class="name">SHOW2</span> <div class="time">August 5, 2015, 1:00 pm - 2:00 pm</div> <div class="desc">Information here.<br/> </div> </div> <div class="col ts ts_1 prog_1045495 ps_3" data-catid="" > <span class="name">SHOW3</span> <div class="time">August 5, 2015, 2:00 pm - 4:00 pm</div> <div class="desc">Information here.<br/> </div> </div> </div> Edited August 5, 2015 by requinix bbcode formatting train wreck Quote Link to comment Share on other sites More sharing options...
codeinphp Posted August 5, 2015 Author Share Posted August 5, 2015 Clean up html <div class="col th"> <a class="channel_sched_link" href="javascript:void(0)" title="TITLE1" data-channelid="1"> <img src="/XXXXX" width="30" height="20" alt="AA" />AA </a> </div> <div class="prog_cols"> <div class="col ts ts_1 prog_1045493 ps_0" data-catid="" > <span class="name">SHOW1</span> <div class="time">August 5, 2015, 11:00 am - 1:00 pm</div> <div class="desc">Information here.<br/> </div> </div> <div class="col ts ts_2 prog_1045494 ps_1" data-catid="" > <span class="name">SHOW2</span> <div class="time">August 5, 2015, 1:00 pm - 2:00 pm</div> <div class="desc">Information here.<br/> </div> </div> <div class="col ts ts_1 prog_1045495 ps_3" data-catid="" > <span class="name">SHOW3</span> <div class="time">August 5, 2015, 2:00 pm - 4:00 pm</div> <div class="desc">Information here.<br/> </div> </div> : Quote Link to comment Share on other sites More sharing options...
codeinphp Posted August 6, 2015 Author Share Posted August 6, 2015 I was able to get this to work foreach ($cols as $col){ $xcid=$col->getElementsByTagName('a'); foreach($xcid as $cids){ $cid[]=$cids->getAttribute('data-channelid'); for($x=0; $x<count($cid); $x++){ foreach ($progname as $name){ $show[]=$name->nodeValue; } $scid[]=$cids->getAttribute('data-channelid'); } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.