Can anybody see any reason why I would get this error?

Notice: Array to string conversion in c:\inetpub\wwwroot\idximportproject\fileimport.php on line 6

<?php
//Load file into variable for tab sorting.
$listingres = file('Listings-Residential.txt');

//Use explode function to put tabbed array into the variable $string
$lines = explode("\t", $listingres);

print_r($lines); //Print out readable data about string

?>

    the second argument for the explode function requires a string, $listingres is an Array since file outputs each line into an Array determined by the operating system new line character e.g. in *nix its \n

      hmmm...it sucks being a newbie, I don't think I completely understand the explode function. I am going to check the syntax in the manual, i will post back

        Maybe I am not going about this correctly. I am trying to read the file and then be able to put the tab separated values into one large database. I was thinking that after reading the file into a variable I could then separate the tab'd data and put it into a large array for separating. since explode() only accepts strings of data, how can I turn my array into one large string? file_get_contents() mabye? which would load all of my data into one large string?

          Yes [man]file_get_contents[/man] would work as it returns the file as a string, however with [man]file[/man] it will read the file except returns an Array of each line like I said before.

            Sorry I am having such a hard time understanding.
            Let me say that my file looks a little something like this.

            95759 RESIDENTIAL SINGLE FAMILY
            95759 RESIDENTIAL SINGLE FAMILY
            95759 RESIDENTIAL SINGLE FAMILY

            I think that you agree with me that using file to read this file in is a good idea. Because every line is read into an array. I just cannot understand how to then make my array into a string so that I can separate all of these tab'd values and then throw them into a database?

              There doesn't look like there'd be a lot of point in putting the array into a string, because you'll only want to turn it back into an array again (of separate records). So file() is the one to go with. And then you'd use a loop to process each line in turn.

              foreach($listingres as $record) // $listingres is the array you got from file()
              { $record=trim($record); // Otherwise the newline character will still be on the end of the line
                $fields = explode("\t", $record);
               // Do stuff with the $fields array.
              }

                Thanks weedpacket, you have a much better method. I spent about an hour working on a solution with a while loop. Thanks!

                  Just as a side note: You asked how you can take an array and turn it into a string--

                  the function is implode()

                    You can also use [man]fgetcsv[/man] and muck about with the delimiter - just saying, like.

                      Write a Reply...