depending on how the text file is organized, this can be an easy task or
impossible.  But, here goes:

If a line in the text file contains all the info about the card and is
organized routinely and separated by a special character ("," , ; or tab,
then you should be able to do something like the following:

<html>
<body bgcolor=navy>
<?php
$db=" ";
$table=" ";
$user=" ";
$pass=" ";
$link=mysql_connect("localhost","$user","$pass");
if (! $link) die("Can't log in at this time");
mysql_select_db($db,$link) or die ("Can't log in at this time");

print "<table align=center cellpadding=7 cellspacing=0 border=1
bgcolor=silver>";

$fp=fopen("persons.txt","r") or die ("Couldn't open file!");

while (!feof ($fp))
 {
 $persons=fgets($fp,100); // looks for \n (carrage return) or 100 characters
before moving on

 list($image,$title,$first,$date,)= split ("\t", $persons, 6);  /// splits
on tab
 print "<tr>
   <td>$first&nbsp;</td>
   <td>$title&nbsp;</td>
   <td>$image&nbsp;</td>
   <td>$date&nbsp;</td>
  </tr>";
 $query="insert into $table (first, title, date, directory, image)
      values ('".addslashes($first)."',
        '".addslashes($title)."',
        '".addslashes($date)."',
        '".addslashes($directory)."',
        '".addslashes($image)."' )";
  $result=mysql_query($query);
  if (!$result) die ("couldn't update $table".mysql_error());
 }
fclose($fp);
mysql_close($link);
print "</table>";
?>
</body>
</html>


----- Original Message -----
From: "John Wulff" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, March 07, 2003 5:25 PM
Subject: [PHP] Mining a file for data


> I'm just learning PHP so please excuse my ignorance.  I'm trying to
extract
> the data from a simply formatted text file via a simple PHP script.  The
> goal of this project is to take Magic the Gathering spoiler lists and dump
> them into a MySQL database.  I've got plenty of experience with MySQL but
> not file parsing.  How do I about parsing this data?  What sort of pattern
> recognition do I use (if that's the right term).
> Thanks for the help.  The format of the file is below.
> -John
>
> Card Name: Akroma, Angel of Wrath
> Card Color: W
> Mana Cost: 5WWW
> Type & Class: Creature - Angel Legend
> Pow/Tou: 6/6
> Card Text: Flying, first strike, trample, haste, protection from black,
>   protection from red. Attacking doesn't cause Akroma, Angel
>   of Wrath to tap.
> Flavor Text: No rest.  No mercy.  No matter what.
> Artist:  Ron Spears
> Rarity:  R
> Card #:  1/145
>
> Card Name: Akroma's Devoted
> Card Color: W
> Mana Cost: 3W
> Type & Class: Creature - Cleric
> Pow/Tou: 2/4
> Card Text: Attacking doesn't cause Clerics to tap.
> Flavor Text: "Akroma asked for only one thing from her troops: unwavering,
>   unconditional loyalty."
> Artist:  Dave Dorman
> Rarity:  U
> Card #:  2/145
>
> etc.. etc...
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


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

Reply via email to