Nandini Posted December 2, 2008 Share Posted December 2, 2008 hi all i am so worrying about php split. i have a textarea field with values as abc=123 qqqqqqq=938 eeeeeee=87373 etc I dont know how much lines of data user will be enter. I want to split that data by line wise and store those values into mysql table as follows. ---------------------------------------------------------------- id keyword data ---------------------------------------------------------------- 1 abc 123 1 qqqqqqq 938 1 eeeeeee 87373 ----------------------------------------------------------- number of lines are not constant. In this scenario number of lines are 3. in future it will be 4 or 7 or 10 etc. Can any one send me script Its urgent , pls Link to comment https://forums.phpfreaks.com/topic/135130-solved-php-split/ Share on other sites More sharing options...
shatner Posted December 2, 2008 Share Posted December 2, 2008 $data = ' abc=123 qqqqqqq=938 eeeeeee=87373 '; $records = explode("\n", $data); // split the data up line by line foreach($records as $record){ // loop through each line $bits=explode('=', $record); // split the line by the '=' $text = trim($bits[0]); // 1st bit of the line $number = trim($bits[1]); // 2nd bit of the line echo $text . '' . $number . '<br>'; // print it back out } Link to comment https://forums.phpfreaks.com/topic/135130-solved-php-split/#findComment-703842 Share on other sites More sharing options...
DarkWater Posted December 2, 2008 Share Posted December 2, 2008 We aren't here to just right scripts for you. Just use explode(), like shatner demonstrated. It's pretty simple. And is there a reason why every row has the same ID? Link to comment https://forums.phpfreaks.com/topic/135130-solved-php-split/#findComment-703844 Share on other sites More sharing options...
Nandini Posted December 2, 2008 Author Share Posted December 2, 2008 Every row has the same id means those details are belongs to one user. So for every user can insert those values. So for every user that id incremented by 1. see this ---------------------------------------------------------------- id keyword data ---------------------------------------------------------------- 1 abc 123 1 qqqqqqq 938 1 eeeeeee 87373 2 abc (2nd user) 123 2 qqqqqqq(2nd user) 938 2 eeeeeee(2nd user) 87373 ----------------------------------------------------------- Hi shatner. Thanx for your help. how can i store these values as shown in the previous table Link to comment https://forums.phpfreaks.com/topic/135130-solved-php-split/#findComment-703862 Share on other sites More sharing options...
Nandini Posted December 2, 2008 Author Share Posted December 2, 2008 topic solved by using insert command within foreach loop. thanx for everyone. Link to comment https://forums.phpfreaks.com/topic/135130-solved-php-split/#findComment-703894 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.