Error message

The spam filter installed on this site is currently unavailable. Per site policy, we are unable to accept new submissions until that problem is resolved. Please try resubmitting the form in a couple of minutes.

PHP Split String by Comma and New Line Characters

Category: 
Tags: 

Use this handy PHP snippet to split a string by commas and new line characters.

// Replace all the new lines with commas, then split (explode) by comma to get each part of the string.
$input = $my_string_with_commas_and_new_lines;
$input = preg_replace("/((\r?\n)|(\r\n?))/", ',', $input);
$pieces = explode(',', $input);
foreach($pieces as $part) {
  print($part);
}

There you have it, tride and true, just for you.

Add new comment