Jump to content

preg_match_all and tables. Help!


lidocayne

Recommended Posts

Hello all!  So I am working on screen scraping a site for my son's rec league.  I seem to be having problem with the pre_match_all syntax.  Here is my code

 


<?php

$url = "http://www.mywebsite.com";
$raw = file_get_contents($url);

$newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
$content = str_replace($newlines, "", html_entity_decode($raw));

$start = strpos($content,'table border="1" cellpadding="1" cellspacing="0"');
$end = strpos($content,'</table>',$start) + 8;

$table = substr($content,$start,$end-$start);

preg_match_all("|<tr(.*)</tr>|U",$table,$rows);
foreach ($rows[0] as $row){

    if ((strpos($row,'<th')===false)){
    
        preg_match_all("|<td(.*)</td>|U",$row,$cells);
        
        $game_date = strip_tags($cells[0][0]);
        
        $game_time = strip_tags($cells[0][1]);
        
        $rink = strip_tags($cells[0][2]);

	$home_team = strip_tags($cells[0][3]);

	$home_score = strip_tags($cells[0][4]); 

	$visiting_team = strip_tags($cells[0][5]);

	$visiting_score = strip_tags($cells[0][6]);
           	
	echo "{$game_date} @ {$game_time} : [{$home_team}] - {$home_score} vs. [{$visiting_team}] - {$visiting_score} <br>\n";

    }

}

?>

 

My issue is that I am trying to get it to only display the data if the team name = x.  I tried to replace the  preg_match_all("|<td(.*)</td>|U",$row,$cells); with  preg_match_all("|Posse|U",$row,$cells);  (Posse is one of the team names).  No luck. 

 

Any input/thoughts?!  Thank you!!

Link to comment
https://forums.phpfreaks.com/topic/227911-preg_match_all-and-tables-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.