Skip to content

Instantly share code, notes, and snippets.

@dustincurrie
Created December 5, 2010 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustincurrie/729560 to your computer and use it in GitHub Desktop.
Save dustincurrie/729560 to your computer and use it in GitHub Desktop.
Safely turn string variable in Drupal (i.e. listing of paths in textfield) into an array and back to a string
<?php
$array = preg_split('/\n/', trim(variable_get('string_variable', '')));
//add remove entries in the array
variable_set('string_variable', implode("\n", $array));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment