How do I replace a comma with a line break using feeds tamper? When trying to import a feed using Feeds and Feeds tamper, I want to insert a new line at the commas (for displaying address in a nice format).

The screenshot shows what I'm trying to achieve:



The result is \n appears in the output

Why is "\n" being inserted rather than a new line?
The problem is to do with single quoted strings and double quoted strings

'\n' !== "\n"


So when you enter \n in the settings it's getting passed to the preg function as a single quoted string and in php there's no safe way of changing the string from a single quoted to a double quoted string.

https://stackoverflow.com/questions/5241748/php-convert-single-quoted-string-to-double-quoted

Solved this using a plugin, 

first make a custom module that adds a ctools feeds_tamper plugin directory

/**
 * @file my_feeds_tamper.module
 */
/**
 * Implements hook_ctools_plugin_directory().
 */
function my_feeds_tamper_ctools_plugin_directory($owner, $plugin) {
  if ($owner == 'feeds_tamper') {
    return 'plugins';
  }
}


Then within that module directory create the plugins directory and add the plugin code

/**
 * @file plugins/comma_to_newline.inc
 * replaces commas with comma linebreak on import
 */

/**
 * defines the ctools plugin
 */
$plugin = array(
  'form' =&gt; 'comma_to_newline_form',
  'callback' =&gt; 'comma_to_newline_callback',
  'name' =&gt; 'Comma to new line',
  'multi' =&gt; 'direct',
  'category' =&gt; 'Text',
);

/**
 * Even though there are no settings we still need the form
 */
function comma_to_newline_form($importer, $element_key, $settings) {
  $form = array();
  return $form;
}

/**
 * replaces a comma (followed by 0 or more spaces) with 
 * a comma and a linebreak
 */
function comma_to_newline_callback($source, $item_key, $element_key, &amp;$field, $settings) {
  $field = preg_replace("/, */", ",\n", $field);
}


I could have made a clone of the preg replace feeds tamper plugin, that replaces \n with "\n", for a more flexible (configurable solution)