Page 1 of 1

Pull and Display Information

Posted: Sat Feb 12, 2011 10:16 am
by strattonh
I looked all over google before I came here and couldn't find anything precisely for this. I know some php I just need to be pointed in the right direction. Basically all I want to is have a script that checks and pulls the Career FG 3PT and Freethrow % from (http://www.nba.com/playerfile/steve_nash/) on a certain interval and takes that displays and updates that on a website I am making so I don't manually have to update after each game... is this possible and where would i get started.

Re: Pull and Display Information

Posted: Sat Feb 12, 2011 2:50 pm
by litebearer
A VERY rough 'sledge-hammer' approach. Note: changes in formatting of your source page may affect results.

Code: Select all

<?PHP
$start_spot = '<h3 class="playerinfo">';
$end_spot = '<div class="playerInfoStatsPlayerInfoBorders">College:';
$file = file_get_contents('http://www.nba.com/playerfile/steve_nash/');
$array_01 = explode($start_spot, $file);
$string = $array_01[1];
$array_02 = explode($end_spot, $string);
$string = $array_02[0];
$array_03 = explode('<dl id="prastats">', $string);
$string = $array_03[1];
$array_04 = explode('<div class="clear"></div>', $string);
$string = $array_04[0];
$string = str_replace(' class="pralast"', "", $string);
$string = str_replace('</dl>', "", $string);
$string = str_replace('\n', "", $string);
$string = str_replace(" ", "", $string);
$string = str_replace("<dt>PPG</dt>", "", $string);
$string = str_replace("<dt>RPG</dt>", "", $string);
$string = str_replace("<dt>APG</dt>", "", $string);
$string = str_replace("<dt>EFF</dt>", "", $string);
$string = str_replace("</dd>", "", $string);
$array_05 = explode('<dd>', $string);
array_shift($array_05);
$string = implode("|", $array_05);
$string = preg_replace("/[^0-9\+\-\.\|]/", "", $string);
$final_array = explode("|", $string);
$prg = $final_array[0];
$rpg = $final_array[1];
$apg = $final_array[2];
$eff = $final_array[3];
echo "PRG = " . $prg . "<br/>";
echo "RPG = " . $rpg . "<br/>";
echo "APG = " . $apg . "<br/>";
echo "EFF = " . $eff . "<br/>";
?>

As to updating on time interval (1) Use CRON to run an update script; or (2) use windows task manager to run script at appointed date/time (accomplish this by having task manager start your browser and point it to the update script).