monkeytooth Posted November 20, 2009 Share Posted November 20, 2009 Ok, im stuck. I havent tempted to build it yet as I cant wrap my mind around it fully at the moment so I am looking for any feedback. I have several large text files that have a csv construct to them. Each text file is several thousand lines deep. First I need to build an array I assume breaking it down line by line. But then I need to take each line and break it further down. So each line becomes chunks of itself based on the csv values. What I am doing is trying to put this information into a database table. Yes, I could use phpmyadmin but 1 its limited to the file size which these file smash that limit to an extreme. 2 phpmyadmin wont let me specify the delimiter for the csv (and if phpmyadmin does, it doesn't on the version my host provides). Example of the layout I need to break down as mentioned above: Raw Info: abc|def|ghi|jkl|mno|pqr|stu|vwx|ya abc|def|ghi|jkl|mno|pqr|stu|vwx|ya abc|def|ghi|jkl|mno|pqr|stu|vwx|ya abc|def|ghi|jkl|mno|pqr|stu|vwx|ya abc|def|ghi|jkl|mno|pqr|stu|vwx|ya abc|def|ghi|jkl|mno|pqr|stu|vwx|ya abc|def|ghi|jkl|mno|pqr|stu|vwx|ya I need to take that and find each line: array[1] = abc|def|ghi|jkl|mno|pqr|stu|vwx|ya array[2] = abc|def|ghi|jkl|mno|pqr|stu|vwx|ya array[3] = abc|def|ghi|jkl|mno|pqr|stu|vwx|ya array[4] = abc|def|ghi|jkl|mno|pqr|stu|vwx|ya array[5] = abc|def|ghi|jkl|mno|pqr|stu|vwx|ya array[6] = abc|def|ghi|jkl|mno|pqr|stu|vwx|ya then I need to make each line break apart into different vars: array2[1] = abc array2[2] = def array2[3] = ghi array2[4] = jkl array2[5] = mno array2[6] = pqr array2[7] = stu array2[8] = vwx array2[9] = yz from there I am just using popping the var's into an insert string and putting them into the DB. My main issue is the thought process, I can't think of how I would break down the loops to do this. Without either causing an endless loop or breaking the loops cause I am building them wrong. Any idea's for this? I know I can use explode to break them down, and filter them individually but how to get them to work with one another sync'd doing both at once is beyond my thought process at the moment. I just need help getting the concept rolling. So if you got an idea please throw it at me. Quote Link to comment https://forums.phpfreaks.com/topic/182336-building-an-array-from-an-array-within-a-loop-ideas/ Share on other sites More sharing options...
Alex Posted November 20, 2009 Share Posted November 20, 2009 What does the data represent? Will each item be a separate record in the database or what? Here's an example of doing what you stated: <?php $text = <<<TEXT abc|def|ghi|jkl|mno|pqr|stu|vwx|ya abc|def|ghi|jkl|mno|pqr|stu|vwx|ya abc|def|ghi|jkl|mno|pqr|stu|vwx|ya abc|def|ghi|jkl|mno|pqr|stu|vwx|ya abc|def|ghi|jkl|mno|pqr|stu|vwx|ya abc|def|ghi|jkl|mno|pqr|stu|vwx|ya abc|def|ghi|jkl|mno|pqr|stu|vwx|ya TEXT; //$file = file('...'); $file = explode("\n", $text); $arr2 = Array(); foreach($file as $line) { $arr[] = $line; $arr2 = array_merge($arr2, explode('|', $line)); } print_r($arr); print_r($arr2); ?> Quote Link to comment https://forums.phpfreaks.com/topic/182336-building-an-array-from-an-array-within-a-loop-ideas/#findComment-962207 Share on other sites More sharing options...
monkeytooth Posted November 20, 2009 Author Share Posted November 20, 2009 gonna have to give that a shoot.. I didn't think laying it out like that would work, Well it didnt work in my head rather.. trying to spin it out. Quote Link to comment https://forums.phpfreaks.com/topic/182336-building-an-array-from-an-array-within-a-loop-ideas/#findComment-962253 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.