Sadly what Olivier suggests below doesn't work and generates the following error message ...... Warning: Array to string conversion in d:\program files\apache group\apache\htdocs\..........\products.php on line 10
It seems that rtrim is converting the array created by @file into a string. What I had been trying to do was to set up some code along the following lines .......... $var1 = @file("mytext_file.txt"); //reads file, creates array $var1 for ($counter=0; Scounter < count($var1); $counter++ { $var2[$counter] = rtrim($var1[$counter], "\n"); } //attempts to loop through each item in the array, trim off the \n and assign to the same item in new array $var2 I'm pretty sure the above doesn't work, though I don't know why. Think I'll go and try it again just in case though as I don't see any obvious errors. There must be a way of running rtrim against every item in an array, trimming the \n and writing each trimmed element to a new array. Any ideas Olivier ..... anyone ? Blu. Olivier Hubert wrote: > I don't know if you pasted the code directly from source, but your problem > might come from the fact that you're using "/n" instead of "\n". > > What I recommend would be this: > $myString = @file('text_file'); > $myArray = rtrim($myString, "\n"); > > Note that for the second part, you might have to put \r and then \n (e.g. > "\r\n") or simply no char specified. By default PHP will strip all > whitespaces, tabs and end of line/NULL bytes when you use rtrim without a > second parameter. You might want to give it a try. > > Hope this helps, > > Olivier Hubert > > At 13:23 2002-05-06 +0100, blulagoon wrote: > >I don't know if this is the right way to go about what I'm trying to do. > > > >In a nutshell, I want to open a simple text file and load the file into > >an array with each line represented by one element in the array. > >Now $myArray = @file("my_text_file"); achieves 90% of what I want, but I > >need to strip out the line feeds at the end of each line that are in the > >original file. > > > >rtrim($myString, "/n") would seem to offer this functionality, but I > >can't figure out the best way to use it with an array ? > > > >Anyone got this working, or is there another easier way to do it, > >perhaps with a variant of file() which doesn't include the linefeeds > >that I don't know about. > > > >Looking forwards to your input guys ..... > > > >Blu. > > > > > >-- > >PHP Windows Mailing List (http://www.php.net/) > >To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php