Added t3lib_div::expandList (turns eg "1,3-5,7" into "1,3,4,5,7")
authorMartin Kutschker <martin.t.kutschker@blackbox.net>
Tue, 19 Apr 2005 09:26:56 +0000 (09:26 +0000)
committerMartin Kutschker <martin.t.kutschker@blackbox.net>
Tue, 19 Apr 2005 09:26:56 +0000 (09:26 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@663 709f56b5-9817-0410-a4d7-c38de5d9e867

t3lib/class.t3lib_div.php

index 20460af..5e80e5c 100755 (executable)
@@ -674,6 +674,29 @@ class t3lib_div {
                return implode(',',$items);
        }
 
+       /**
+        * Expand a comma-separated list of integers with ranges (eg 1,3-5,7 becomes 1,3,4,5,7).
+        *
+        * @param       string          $list   comma-separated list of integers with ranges (string)
+        * @return      string          new comma-separated list of items
+        * @author      Martin Kutschker <martin.kutschker@activesolution.at>
+        */
+       function expandList($list)      {
+               $items = explode(',',$list);
+               $list = array();
+               while(list(,$item)=each($items))        {
+                       $range = explode('-',$item);
+                       if (isset($range[1]))   {
+                               for ($n=$range[0]; $n<=$range[1]; $n++)
+                                       $list[] = $n;
+                       } else {
+                               $list[] = $item;
+                       }
+               }
+
+               return implode(',',$list);
+       }
+
        /**
         * Forces the integer $theInt into the boundaries of $min and $max. If the $theInt is 'false' then the $zeroValue is applied.
         * Usage: 224