This blog site is not meant to be any information that is distributed to the general public. It is to serve as shared documentation between the DNSTC developers; however, if you find something useful and would like to use it, go right ahead.

Saturday, January 28, 2012

Reading a Textarea Field Into Separate Lines

imageOn occasion, you may run into the need to create a small utility the will read each line of a textarea field and process each line separately.  I have done this on a few occasions (like the domain upload for or the Quick Task function on 

Here is the code:

1.  You setup a field in your form that is a textarea, let’s call it dataList.

2. On the processing side, you would use the following code:

$dataList = trim($_POST['dataList']);
$dataProcess = explode("\n", $dataList);

foreach ($dataProcess as $line) {

$cleanData = trim($line);

process $cleanData



The first trim will remove the carriage return bit at the end of the data, the second trim within the foreach loop, will remove the carriage return at the end of each line.  I have seen examples of this where it used the second trim above, but it does not leave the ability to split the data into the $dataProcess array.

That is pretty much how you do that.  Works pretty good.

No comments:

Post a Comment