On 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 YourPopLinks.com or the Quick Task function on DNSTCcontact.com).
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