Re: Subject: grabbing text from a webpage and putting it in a query.

From: Date: Sat, 03 Jan 2004 11:31:31 +0000
Subject: Re: Subject: grabbing text from a webpage and putting it in a query.
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-32254@lists.php.net to get a copy of this message
At 01:49 03/01/2004 +0000, you wrote:
Message-ID: <20040103010411.7896.qmail@web41211.mail.yahoo.com> Date: Sat, 3 Jan 2004 12:04:11 +1100 (EST) From: JeRRy <jusa_98@yahoo.com> To: php-db@lists.php.net MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Subject: grabbing text from a webpage and putting it in a query.
All I can suggest is that you cut and paste the desired text into notepad and save it as a file. This is because their pages are not regular nor xhtml (or even well formed HTML) that you cannot parse the page reliably. So, cut and paste the text only and save it first using notepad, before loading it into PHP and slicing it up into an array of lines. Then try using a regular expression in a loop, to create your INSERT query. This might work for one of your team lines (untested so you'll have to look through the preg expression syntax to check how to split the lines correctly it if it doesn't work ;-) $matcharray=array("Brisbane Lions v Collingwood at Gabba (night)");
//      Assumes you set up a loop and are capable to split
//      your text by newlines into an array of strings
foreach ($matcharray as $string) {
        $matching="/^([a-z ]+) v ([a-z ]+) at .*/iu";
        $matches=array();
        if (preg_match($matching,$string,$matches)) {
                $query="INSERT INTO games (team1, team2)
                        VALUES ('".$matches[1]."','".$matches[2]."')";
//              mysql_query($query,$link);
                print($query);
        }
}
So is there a way to grab text from an external website (away from my server) and put it in a query I setup on my site? I'm seeking the text, not the HTML or source. At pressent I am copying the rounds into notepad and entering them in the database 1 by 1. This takes ages as there is 16 teams in each round and 22 rounds. :P Takes alot of time to complete so was looking for a faster way. :) Any ideas? Thanks! J


« previous php.db (#32254) next »