PHP Split String by Comma and New Line Characters

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) {

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

Drupal - Post Data via Ajax to PHP Menu Callback with JQuery and JSON

Drupal 7

I found this solid example for Drupal 7.

The code for D7 is much more elegant, there are some great new features in D7 to make this stuff easier.

Drupal 6

Put this PHP code inside your module, e.g. sites/all/modules/my_module/my_module.module

List of United States and Abbreviations in Various Code Forms


From abbreviation to name...

Subscribe to RSS - php