lifeson2112 Posted March 17, 2007 Share Posted March 17, 2007 ok, I have a slight problem. I need to read in information from a bunch of .xls spreadsheets into my database by first converting them into tab-delimited text files, but one of the columns is full of sentences with new lines. I cut that column out, put it in a separate .xls file, and made a .txt file out of it. Here's some info about how my program (gnumeric) changed it: Each column (1 column in this case) is separated by a tab (checked the file for tabs using str_replace() and there aren't any). and there is a carriage return at the end of each row. I want to keep the carriage returns in tact so I can know how to explode the file. Here's some of my code so you can see how I have attempted to do this: <?php $file = file("power_wheels_caption.txt"); $rows = count($file); for($i=0; $i<$rows; $i++) { $noendlines[$i] = str_replace("\n"," ", $file[$i]); } $implodedstring = implode(" ",$noendlines); $captionarray = explode("\r",$implodedstring); $newfile = fopen("temp_caption.txt", 'w') or die("could not open file"); $newrow = count($captionarray); for($j=0; $j<$newrow; $j++) { fwrite($newfile, $captionarray[$j]."\r") or die("could not open file"); } ?> I am planning then to take the "temp_caption.txt", read it into gnumeric again and paste the resulting cells back into the table, where it can be whole again. This will save a lot of time if someone can help me figure this out. Thanks in advance . Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.