Can someone see clearly through what I'm trying to do please?
I've been at this for 4 hours trying to see where I have gone wrong.

##### contents of a text file #############################
Enregistrement
TI: ... So They Understand ...: Cultural Issues
AU: Schneider,-William
PB: Logan, UT : Utah State UP, 2002. 198 pp.
Enregistrement
TI: La Favilla and Italian Ethnicity in Canada
AU: Gualtieri,-Antonio-Roberto
SOM: Canadian-Ethnic-Studies/Etudes-Ethniques-au-Canada
###################################################

I have the text above in a textfile that I upload:
I want to separate it into two records.
Then I want to parse each line so that each value:

$TI, $AU, $PB and $SOM

equal the contents of the rest of the line, so I can build some SQL.

AU: Gualtieri,-Antonio-Roberto

$AU = "Gualtieri,-Antonio-Roberto";

The problem is that in the end, $sql holds nothing meaningful.

And because I'm filtering from one database type to my own set of
values,

$TI, $AU, $PB and $SOM

MUST become:

$ST, $AU, $BT and $JR

so I refer to this array:

###################################################
###################################################
$var = array (
 'TI' => array (
 'Description' => 'Title: (TI)',
 'Option'      => 'ST',
 ),
 'AU' => array (
 'Description' => 'Author(s): (AU)',
 'Option'      => 'AU',
 ),
 'PB' => array (
 'Description' => 'Publication Information: (PB)',
 'Option'      => 'BT',
 ),
 'SOM' => array (
 'Description' => 'Source (Bibliographic Citation): (SO)',
 'Option'      => 'JR',
 )
);
###################################################
###################################################

Here is my code, or what is left of it.
Please help me make sense so I make $sql work.:

###################################################
###################################################

$fh=fopen($_FILES['userfile']['tmp_name'], 'r');
...
$fileContents=fread($fh, filesize($_FILES['userfile']['tmp_name']));
...
$lines=explode("Enregistrement",$fileContents);

foreach($lines as $line) {

 $line = stripslashes($line);
 $line = str_replace("\r", "", $line);

 $newlines=explode("\n",$line);

  foreach($newlines as $newline)
  {
   foreach ($var as $key => $value)
   {
# This foreach should parse each record line,
# looking in $var to find the corresponding
# value so that:
# $TI, $AU, $PB and $SOM
# become:
# $ST, $AU, $BT and $JR

   if(!$$key){$$key = filter_strings("$key:",$line);}

# breaking each line into two values so that:
# $TI = "So They Understand ..."
# $AU = "Schneider..."
# $BT = "Logan, UT..."
# etc.

#I'm f***ing up in here someplace. What should I put back in?

$sql = "insert into ".$dbtable." (ST,AU,BT,JR) VALUES
('".$ST."','".$AU."','".$BT."','".$JR."');";

   }
  }#end of foreach($newlines as $newline)

}#end of foreach($lines as $line)


echo $sql;


function filter_strings($tofilter,$line){
  if(eregi('^'.$tofilter.'(.*)$',$line,$m)) {
        $filtered=$m[1];
        return $filtered;
     }
}


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

Reply via email to