Jump to content

[SOLVED] Make a textarea value into an array insert according to comma, line break, etc


msaz87

Recommended Posts

Hey all,

 

I was just curious if anyone had an example or could point me in the direction of something that would describe the process of making the values of a textarea into an array based on some sort of defined factor, such as a comma, a line break, etc.

 

In other words... if the contents of a text area were:

 

One, Two, Three, Four

 

Then each one of those words would insert separately into the DB

 

Any help is greatly appreciated. Thanks!

I guess I need a little more help than I thought..

 

So if my textarea is:

 

<textarea name="divisions[]" cols="40" rows="5"></textarea>

 

And the code on the process page is:

 

$divisions 	= array_map( 'trim', explode( ',', $_POST['divisions[]'] ) );	

 

How would I echo that to make sure it's working properly and how would I then go about doing some sort of foreach to insert each separately into the DB?

 

Thanks again

something like this:

$text =$_POST['divisions'];
$array = explode(",",$text);
// print array values using print_r function
echo "<pre>".print_r($array,true)."</pre>";

// print array values using foreach loopos
foreach($array as $value){
echo "$value <br />";
}

Is there any particular reason you named your textarea with name="divisions[]"?

 

It was just me doing some stupid things because I had no idea what I was doing....

 

But PHPFreaksMaster's solution worked perfectly -- thanks for all the help!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.