Jump to content

PHP Parse Muiltiple HTML Tags


codeinphp

Recommended Posts

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 by requinix
bbcode formatting train wreck
Link to comment
Share on other sites

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>

 

:

Link to comment
Share on other sites

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');
}


} 
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.