Splitting a text field into an array

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
uiteja
Posts: 6
Joined: 2015-12-07 21:28
Location: the Netherlands
Contact:

Splitting a text field into an array

Post by uiteja » 2015-12-09 20:11

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.

User avatar
a.gneady
Site Admin
Posts: 1354
Joined: 2012-09-27 14:46
Contact:

Re: Splitting a text field into an array

Post by a.gneady » 2015-12-10 21:44

Is the field Knd set as a text area or a rich text area?
:idea: AppGini plugins to add more power to your apps:

uiteja
Posts: 6
Joined: 2015-12-07 21:28
Location: the Netherlands
Contact:

Re: Splitting a text field into an array

Post by uiteja » 2015-12-11 21:34

No.

uiteja
Posts: 6
Joined: 2015-12-07 21:28
Location: the Netherlands
Contact:

Re: Splitting a text field into an array

Post by uiteja » 2015-12-12 18:00

The field is set as a text area.

User avatar
a.gneady
Site Admin
Posts: 1354
Joined: 2012-09-27 14:46
Contact:

Re: Splitting a text field into an array

Post by a.gneady » 2015-12-14 05:57

If \n doesn't work, try <br>

Code: Select all

$Stem_arr = explode("<br>", $data['Knd']); 
:idea: AppGini plugins to add more power to your apps:

uiteja
Posts: 6
Joined: 2015-12-07 21:28
Location: the Netherlands
Contact:

Re: Splitting a text field into an array

Post by uiteja » 2015-12-16 21:13

$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.

uiteja
Posts: 6
Joined: 2015-12-07 21:28
Location: the Netherlands
Contact:

Re: Splitting a text field into an array

Post by uiteja » 2016-01-08 07:31

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.

Post Reply