Reputation: 213
In my form: I have 8 checkboxes that will save to MySQL as a string/varchar (not an int).
Ex:
Now, I want to output this to 3 different fields with limited number of characters per field.
If all checkboxes are check and save into MySQL, the output will be:
Apple, Orange, Mango
(this field can only hold 25 characters, so I have to put the next variable data into FIELD 2).Grape, Watermelon
(this field can only hold 25 characters, so I have to put the next variable data into 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?
Upvotes: 0
Views: 117
Reputation: 12721
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);
Upvotes: 2