TheMunky Posted June 1, 2006 Share Posted June 1, 2006 Hey guys, I just registered a couple of minutes ago. I am pretty novice at PHP, and was wondering if you guys could help me out with this problem I have. Basically, I want to be able to convert a string that contains columns of text and make each column its own string (or put the contents into an array). Here's an example:say I have $test = " 123 456 891nnn jjj kkklol jkl lol"I would want to put say column 1, which is 123, nnn, lol into its own string. I only know how to do this in visual basic, not php, but would it involve something like searching for spaces in each line?Thanks in advance for any help! Quote Link to comment https://forums.phpfreaks.com/topic/10918-converting-columns-into-substrings/ Share on other sites More sharing options...
hvle Posted June 1, 2006 Share Posted June 1, 2006 [!--quoteo(post=378929:date=Jun 1 2006, 01:26 PM:name=TheMunky)--][div class=\'quotetop\']QUOTE(TheMunky @ Jun 1 2006, 01:26 PM) [snapback]378929[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hey guys, I just registered a couple of minutes ago. I am pretty novice at PHP, and was wondering if you guys could help me out with this problem I have. Basically, I want to be able to convert a string that contains columns of text and make each column its own string (or put the contents into an array). Here's an example:say I have $test = " 123 456 891nnn jjj kkklol jkl lol"I would want to put say column 1, which is 123, nnn, lol into its own string. I only know how to do this in visual basic, not php, but would it involve something like searching for spaces in each line?Thanks in advance for any help![/quote]$data = '123 456 891nnn jjj kkklol jkl lol'knowing how to use the wonderful 'explode' function in PHP is a must to all.first of all, your data's column is separated by space, and the rows separate by new line:$rows = explode("\n", $data);now, $rows[0] is '123 456 891', $rows[1] is 'nnn jjj kkk' .. and so on.$cols = explode(' ', $rows[0]);then, $cols[0] will be 123, $cols[1] will be 456.. and so on.if you put them together in a loop, you'll get what you wanted.Tom Quote Link to comment https://forums.phpfreaks.com/topic/10918-converting-columns-into-substrings/#findComment-40784 Share on other sites More sharing options...
TheMunky Posted June 1, 2006 Author Share Posted June 1, 2006 Figured it out, thanks for all the help! Quote Link to comment https://forums.phpfreaks.com/topic/10918-converting-columns-into-substrings/#findComment-41049 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.