soycharliente Posted January 28, 2010 Share Posted January 28, 2010 I'm trying to create a form that would batch process data rather than using one form to submit multiple entries. I'm having trouble just splitting the data between each line. I've tried two different ways so far and neither do what I want. Right now I'm just trying to split each line into an array element. I'm taking it in steps. First way: /* Batch button */ if (isset($_POST['BatchSubmit']) && $_POST['BatchSubmit'] == 'Add') { foreach ($_POST as $key => $val) { $_POST[$key] = makeSafe(trim($val)); } $batch = $_POST['batch']; $lines = explode("\r\n", $batch); print_r($lines); } Second way: /* Batch button */ if (isset($_POST['BatchSubmit']) && $_POST['BatchSubmit'] == 'Add') { foreach ($_POST as $key => $val) { $_POST[$key] = makeSafe(trim($val)); } $batch = nl2br($_POST['batch']); $lines = explode('<br />', $batch); print_r($lines); } Any help with a function I should look at? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/190130-batch-process-multiline-input-from-textarea/ Share on other sites More sharing options...
soycharliente Posted January 28, 2010 Author Share Posted January 28, 2010 I don't know why it's working now, but it is. Maybe it's the single quotes. Before I was using double. $lines = explode('\r\n', $batch); The issue I'm having now is when there's an error, I output the input back into the textarea. However, it inserts \r\n into the text. How can I get it to display exactly how it was inputted? Quote Link to comment https://forums.phpfreaks.com/topic/190130-batch-process-multiline-input-from-textarea/#findComment-1003181 Share on other sites More sharing options...
premiso Posted January 28, 2010 Share Posted January 28, 2010 $lines = explode("\r\n", $batch); You need double quotes for \r\n to be taken as their real characters. The single quotes takes the literally. Quote Link to comment https://forums.phpfreaks.com/topic/190130-batch-process-multiline-input-from-textarea/#findComment-1003184 Share on other sites More sharing options...
soycharliente Posted January 28, 2010 Author Share Posted January 28, 2010 Are you saying I should NOT use single quotes? It didn't explode properly when I did use double quotes. It works as wanted when I use single. When I pull the information from the $_POST array, it has those literal characters in it. Quote Link to comment https://forums.phpfreaks.com/topic/190130-batch-process-multiline-input-from-textarea/#findComment-1003185 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.