Jack
01-04-2003, 19:13
Hey all...
Here is some php code that will parse the usfirst team list for the champ event for you. You can change the echo's to assign the fields to an array which you could insert into your db. If you have any questions, feel free to ask me.
<?php
//Team Parser for The 2003 FIRST Champ. Event
//Designed by: Andrew Schenk (email: webmaster@feds201.com)
//Code tested on PHP 4.3.1 - (should work on any 4+ version & mabey 3 depending on some functions)
//Known Bugs:
//The current source code for the team website is not correct. It is missing the "" around the url.
//If first decides to correct this error do the following to the code:
/*
--find--
echo substr($var, (strpos($var, 'href=')+5), (strpos($var, '>') - strpos($var, 'href=')-5)).'<br />';
--replace with--
echo substr($var, (strpos($var, 'href="')+6), (strpos($var, '">') - strpos($var, 'href="')-6)).'<br />';
*/
//I'm 99% sure that would correct the code, but not sure exactly how they would change it so... who knows?
//to actually use the code, replace the echo statements with an array var and then you could dump that array into your db
//hehe... actually going to include a few comments...
//--get source code from usfirst--//
$source = '';
@ $source_pointer = fopen('http://www.usfirst.org/frc/map/FMPro?-db=team%20events.fp5&-lay=web&-format=team_list.htm&event=CMP&event%20year=2003&status=signed%20up&-sortfield=team%20id&-max=all&-find', "r");
if ( $source_pointer === false )
{
die('Could not open url');
}
while ( !feof($source_pointer) )
{
$source .= fread($source_pointer, 1024);
}
fclose($source_pointer);
$x = 0; //$x is going to be the var to hold our string offset in all the strpos() functions
while ( strpos($source, '<TR BGCOLOR="#FFFFFF">', $x) > $x )
{
echo '<hr>';
$x = strpos($source, '<TR BGCOLOR="#FFFFFF">', $x) + 22; //find the start of a new record (<tr>) and then offset the pointer to the end of it
while ( strpos($source, '</TR>', $x) > strpos($source, '<TD class="news">', $x) && strpos($source, '<TD class="news">', $x) > $x )
{
$x = strpos($source, '<TD class="news">', $x) + 17; //find the start of a new field and offset the pointer to the end
$var = trim(substr($source, $x, (strpos($source, '</TD>', $x) - $x))); //assign the field to the var
if ( strpos($var, '<A') !== false ) //decide if the var has a link in it
{
echo substr($var, (strpos($var, 'href=')+5), (strpos($var, '>') - strpos($var, 'href=')-5)).'<br />'; //get url from link
$var = strip_tags($var); //return the team name
echo $var;
} else {
echo $var.'<br />'; //return a var without a link
}
}
}
//--the end--//
?>
Here is some php code that will parse the usfirst team list for the champ event for you. You can change the echo's to assign the fields to an array which you could insert into your db. If you have any questions, feel free to ask me.
<?php
//Team Parser for The 2003 FIRST Champ. Event
//Designed by: Andrew Schenk (email: webmaster@feds201.com)
//Code tested on PHP 4.3.1 - (should work on any 4+ version & mabey 3 depending on some functions)
//Known Bugs:
//The current source code for the team website is not correct. It is missing the "" around the url.
//If first decides to correct this error do the following to the code:
/*
--find--
echo substr($var, (strpos($var, 'href=')+5), (strpos($var, '>') - strpos($var, 'href=')-5)).'<br />';
--replace with--
echo substr($var, (strpos($var, 'href="')+6), (strpos($var, '">') - strpos($var, 'href="')-6)).'<br />';
*/
//I'm 99% sure that would correct the code, but not sure exactly how they would change it so... who knows?
//to actually use the code, replace the echo statements with an array var and then you could dump that array into your db
//hehe... actually going to include a few comments...
//--get source code from usfirst--//
$source = '';
@ $source_pointer = fopen('http://www.usfirst.org/frc/map/FMPro?-db=team%20events.fp5&-lay=web&-format=team_list.htm&event=CMP&event%20year=2003&status=signed%20up&-sortfield=team%20id&-max=all&-find', "r");
if ( $source_pointer === false )
{
die('Could not open url');
}
while ( !feof($source_pointer) )
{
$source .= fread($source_pointer, 1024);
}
fclose($source_pointer);
$x = 0; //$x is going to be the var to hold our string offset in all the strpos() functions
while ( strpos($source, '<TR BGCOLOR="#FFFFFF">', $x) > $x )
{
echo '<hr>';
$x = strpos($source, '<TR BGCOLOR="#FFFFFF">', $x) + 22; //find the start of a new record (<tr>) and then offset the pointer to the end of it
while ( strpos($source, '</TR>', $x) > strpos($source, '<TD class="news">', $x) && strpos($source, '<TD class="news">', $x) > $x )
{
$x = strpos($source, '<TD class="news">', $x) + 17; //find the start of a new field and offset the pointer to the end
$var = trim(substr($source, $x, (strpos($source, '</TD>', $x) - $x))); //assign the field to the var
if ( strpos($var, '<A') !== false ) //decide if the var has a link in it
{
echo substr($var, (strpos($var, 'href=')+5), (strpos($var, '>') - strpos($var, 'href=')-5)).'<br />'; //get url from link
$var = strip_tags($var); //return the team name
echo $var;
} else {
echo $var.'<br />'; //return a var without a link
}
}
}
//--the end--//
?>