+ //explode the clean string into lines again
+ $lines = explode("\n",$clean);
+
+ //now process each line at a time
+ for($i=0;$i<count($lines);$i++)
+ {
+ $line = $lines[$i];
+
+ //remove comments
+ $line = preg_replace("/\/\/(.*)/","",$line);
+
+ //strip leading and trailing whitespace
+ $line = trim($line);
+
+ //remove all whitespace with a single space
+ $line = preg_replace("/\s+/"," ",$line);
+
+ //remove any whitespace that occurs after/before an operator
+ $line = preg_replace("/\s*([!\}\{;,&=\|\-\+\*\/\)\(:])\s*/","\\1",$line);
+
+ $lines[$i] = $line;
+ }
+
+ //implode the lines
+ $sJS = implode("\n",$lines);
+
+ //make sure there is a max of 1 \n after each line
+ $sJS = preg_replace("/[\n]+/","\n",$sJS);
+
+ //strip out line breaks that immediately follow a semi-colon
+ $sJS = preg_replace("/;\n/",";",$sJS);
+
+ //curly brackets aren't on their own
+ $sJS = preg_replace("/[\n]*\{[\n]*/","{",$sJS);
+
+ //finally loop through and replace all the literal strings:
+ for($i=0;$i<count($literal_strings);$i++) {
+ if (strpos($literal_strings[$i],"/*")!==false)
+ $literal_strings[$i]= '';
+ $sJS = str_replace("___".$i."___",$literal_strings[$i],$sJS);
+ }
+ return $sJS;
+}
+//-----------------------------------------------------------------------------
+// Inserts $elements into $array at position $index.
+// $elements is list of any objects
+//
+function array_insert(&$array, $index, $elements)
+{
+ if (!is_array($elements)) $elements = array($elements);
+
+ $head = array_splice($array, 0, $index);
+ $array = array_merge($head, $elements, $array);
+}
+
+function array_remove(&$array, $index, $len=1)
+{
+ array_splice($array, $index, $len);
+}
+
+function array_replace(&$array, $index, $len, $elements)
+{
+ array_splice($array, $index, $len);
+ array_insert($array, $index, $elements);
+}
+
+function array_append(&$array, $elements)
+{
+ foreach($elements as $key => $el) {
+ if(is_int($key))
+ $array[] = $el;
+ else
+ $array[$key] = $el;
+ }
+}
+