msaz87 Posted November 14, 2009 Share Posted November 14, 2009 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! Link to comment https://forums.phpfreaks.com/topic/181472-solved-make-a-textarea-value-into-an-array-insert-according-to-comma-line-break-etc/ Share on other sites More sharing options...
roopurt18 Posted November 14, 2009 Share Posted November 14, 2009 $words = array_map( 'trim', explode( ',', $_POST['textarea'] ) ); Link to comment https://forums.phpfreaks.com/topic/181472-solved-make-a-textarea-value-into-an-array-insert-according-to-comma-line-break-etc/#findComment-957284 Share on other sites More sharing options...
msaz87 Posted November 14, 2009 Author Share Posted November 14, 2009 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 Link to comment https://forums.phpfreaks.com/topic/181472-solved-make-a-textarea-value-into-an-array-insert-according-to-comma-line-break-etc/#findComment-957306 Share on other sites More sharing options...
PHPFreaksMaster Posted November 14, 2009 Share Posted November 14, 2009 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 />"; } Link to comment https://forums.phpfreaks.com/topic/181472-solved-make-a-textarea-value-into-an-array-insert-according-to-comma-line-break-etc/#findComment-957333 Share on other sites More sharing options...
roopurt18 Posted November 15, 2009 Share Posted November 15, 2009 Is there any particular reason you named your textarea with name="divisions[]"? Link to comment https://forums.phpfreaks.com/topic/181472-solved-make-a-textarea-value-into-an-array-insert-according-to-comma-line-break-etc/#findComment-957760 Share on other sites More sharing options...
msaz87 Posted November 15, 2009 Author Share Posted November 15, 2009 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! Link to comment https://forums.phpfreaks.com/topic/181472-solved-make-a-textarea-value-into-an-array-insert-according-to-comma-line-break-etc/#findComment-957847 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.