I have a textarea that I want the user to be able to enter variables into (one variable per line). When they click submit I then send what they’ve entered with a jQuery post to a php script like so:
$('#submit').click(function() {
variables = $('#variables').val();
$.post('script.php', { "variables": variables }, function(data) {
}, 'json');
});
I recieve the string ok in the script easily with:
$variables = $_POST['variables'];
but how would I split this string of variables into an array? I have tried:
$variableList = explode("\r\n", $variables);
preg_replace("\r\n", '<br />', $variables);
str_replace("\r\n", '<br />', $variables);
Can anyone help please?
Although you didn’t specify your SO, I believe the problem is because you’re not splitting the right thing:
Instead of:
Try: