sandy1028 Posted August 27, 2007 Share Posted August 27, 2007 Hi, I am not able to explode further what is the problem. data.txt User1 : 0 : 1 : 2|user2 : 132 : 133 : 134|User3 : 223 : 233 : 245|User4 : 334 : 39: 334|User5 : 423 : 433: 435|User6 : 52 : 53: 55|User7 : 633 : 633: 634|User8 : 623 : 7: 74|User9 : 83 : 853: 845|User10 : 93 : 923 : 945|User11 : 623 : 623: 645|User12 : 23 : 23 : 45|User13 : 23 : 23 : 45|User14 : 23 : 23 : 45|User15 : 23 : 23 : 45|User16 : 23 : 23 : 45|User17 : 23 : 23 : 45|User18 : 23 : 23 : 45|User19 : 23 : 23 : 45|User20 : 23 : 23 : 45|User21 : 23 : 23 : 45|User22 : 23 : 23 : 45|User23 : 23 : 23 : 45|User24 : 23 : 23 : 45 $data="data.txt"; foreach($data as $line){ $text_line=explode("|",$line); foreach($text_line as $text){ $tex=explode(":",$text); foreach($tex as $t){ $te=explode(" ",$t); } } } Quote Link to comment https://forums.phpfreaks.com/topic/66843-explode-problem/ Share on other sites More sharing options...
sandy1028 Posted August 27, 2007 Author Share Posted August 27, 2007 Split the string into array. After explode I get the values as $te[0] as user1 user2.... $te[1] as 0 1 2 132 133 134..... How to split $te[1] again Quote Link to comment https://forums.phpfreaks.com/topic/66843-explode-problem/#findComment-335096 Share on other sites More sharing options...
wildteen88 Posted August 27, 2007 Share Posted August 27, 2007 Try the attached code below. It'll load each user into their own separate array, example: [user1] => Array ( [0] => 0 [1] => 1 [2] => 2 ) [user2] => Array ( [0] => 132 [1] => 133 [2] => 134 ) The code: <?php $data = file("data.txt"); foreach($data as $line) { $text_line = explode("|",$line); foreach($text_line as $text) { list($user, $col1, $col2, $col3) = array_map('trim', explode(":", $text)); $users[$user] = array($col1, $col2, $col3); } } echo '<pre>' . print_r($users, true) . '</pre>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/66843-explode-problem/#findComment-335164 Share on other sites More sharing options...
pl_harish Posted August 27, 2007 Share Posted August 27, 2007 can you post a sample of the actual file and what you want to do with it. regards, Harish www.harishpalaniappan.com www.floresense.com Quote Link to comment https://forums.phpfreaks.com/topic/66843-explode-problem/#findComment-335166 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.