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