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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



----
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);
         }
}

----


Thanks for your response....

<QUOTE>
$matcharray=array("Brisbane Lions v Collingwood at
Gabba (night)");
</QUOTE>

This will only work for that game matching the names
right?  I'd like to run some query or maybe 2 or 3 MAX
to get the entries on the DB.  That would mean I'd
have to edit the array on each game?  Is it possible
to look for ALL instances of 'v' and grab the names
before and after it?  This is complicated.  I could be
wrong here but your example above I'd have to change
the array each time to get each game?

Or a shortcut, if there was some sorta tool online
that I could use that grabs a text file upload that
outputs the insert values automatically when you
upload.  With each insert upload seperated by the
<enter> key.

So if I uploaded:

team 1 v team 2
team 3 v team 4
team 5 v team 6

It would output:

INSERT into whatever team1, team2);
INSERT into whatever team3, team4);
INSERT into whatever team5, team6);

Or finding a script that is that clever, might be
available??? I dunno... Might go look. :)

J



http://personals.yahoo.com.au - Yahoo! Personals
New people, new possibilities. FREE for a limited time.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux