Page 1 of 1

Splitting a text field into an array

Posted: 2015-12-09 20:11
by uiteja
I have a text field.
In hooks (before update) i want to put every line of the text field in an element of an array.
I tried using:
$Stem_arr = explode("\n", $data['Knd']);
This did not work.

Re: Splitting a text field into an array

Posted: 2015-12-10 21:44
by a.gneady
Is the field Knd set as a text area or a rich text area?

Re: Splitting a text field into an array

Posted: 2015-12-11 21:34
by uiteja
No.

Re: Splitting a text field into an array

Posted: 2015-12-12 18:00
by uiteja
The field is set as a text area.

Re: Splitting a text field into an array

Posted: 2015-12-14 05:57
by a.gneady
If \n doesn't work, try <br>

Code: Select all

$Stem_arr = explode("<br>", $data['Knd']); 

Re: Splitting a text field into an array

Posted: 2015-12-16 21:13
by uiteja
$Stem_arr = explode("<br>", $data['Knd']);
did not work.
I found out that in my case the following statement did work:
explode("r", $data['Knd']);
In my text field there are only numbers, otherwise this would be not usefull.

Re: Splitting a text field into an array

Posted: 2016-01-08 07:31
by uiteja
Problem solved.
1] find out which characters are used for return new line:
$hlp=bin2hex(".........") for the dots you copy two short lines in the text field for example
A
A
Print $hlp: yoy can see which characters are used for A en in between the characters for return newline
(in my example with utf8: hex 5c725c6e).
2] put the characters in a variable for return new line:
$r=hex2bin("5c725c6e");
3] Now you can explode a text field with:
explode($r,$data['Stem']);
Stem is the name of the text field.