Jump to content

[SOLVED] php split


Nandini

Recommended Posts

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
Share on other sites

$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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.