topical media & game development

talk show tell print

professional-sql-04-lib-functions.php / php



  <?php
  // convert a list of items (separated by newlines by default) into an array
  // omitting blank lines and optionally duplicates
  function explode_items(text, separator = "\n", preserve = true)
  {
      items = array();
      foreach (explode(separator, text) as value)
      {
          tmp = trim(value);
          if (preserve)
          {
               items[] = tmp;
          }
          else
          {
              if (!empty(tmp))
              {
                  items[tmp] = true;
              }
          }
      }
  
      if (preserve)
      {
          return items;
      }
      else
      {
          return array_keys(items);
      }
  }
  ?>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.