Separate data into 3 fields
In my form: I have 8 checkboxes that will save to MySQL as a string/varchar (not an int).
Ex:
- Checkbox 1 = Apple
- Checkbox 2 = Orange
- Checkbox 3 = Mango
- Checkbox 4 = Grape
- Checkbox 5 = Watermelon
- Checkbox 6 = Melon
- Checkbox 7 = Pineapple
- Checkbox 8 = Cherry
Now, I want to output this to 3 different fields with limited number of characters per field.
- Field 1 = Has a limit of 25 Characters
- Field 2 = Has a limit of 30 Characters
- Field 3 = Has an unlimited Characters
If all checkboxes are check and save into MySQL, the output will be:
- FIELD 1:
Apple, Orange, Mango
(this field can only hold 25 characters, so I have to put the next variable data into FIELD 2). - FIELD 2:
Grape, Watermelon
(this field can only hold 25 characters, so I have to put th开发者_C百科e next variable data into FIELD 3). - FIELD 3:
Melon, Pineapple, and Cherry
I did some research on STRLEN, EXPLODE, etc. and somehow I can't put this together in PHP. How could I do it?
Perhaps wordwrap will do the trick? One way of doing it is (not tested):
$string_list = explode("\n", wordwrap($string, 25));
$field1 = array_shift($string_list);
$string = implode(" ",$string_list);
$string_list = explode("\n", wordwrap($string, 30));
$field2 = array_shift($string_list);
$field3 = implode("\n", $string_list);
精彩评论