+// Remove redundant values from array()
+function array_unique_recursive($array = array())
+{
+ if (! is_array($array)) return $array;
+
+ $tmp = array();
+ foreach($array as $key => $value){
+ if (is_array($value)) {
+ $array[$key] = array_unique_recursive($value);
+ } else {
+ if (isset($tmp[$value])) {
+ unset($array[$key]);
+ } else {
+ $tmp[$value] = TRUE;
+ }
+ }
+ }
+
+ return $array;
+}
+
+// Roughly strings(1) using PCRE
+// This function is useful to:
+// * Reduce the size of data, from removing unprintable binary data
+// * Detect _bare_strings_ from binary data
+// References:
+// http://www.freebsd.org/cgi/man.cgi?query=strings (Man-page of GNU strings)
+// http://www.pcre.org/pcre.txt
+function strings($binary = '', $min_len = 4, $ignore_space = FALSE)
+{
+ if ($ignore_space) {
+ $binary = preg_replace(
+ array(
+ '/(?:[^[:graph:] \t\n]|[\r])+/s',
+ '/[ \t]{2,}/',
+ '/^[ \t]/m',
+ '/[ \t]$/m',
+ ),
+ array(
+ "\n",
+ ' ',
+ '',
+ ''
+ ),
+ $binary);
+ } else {
+ $binary = preg_replace('/(?:[^[:graph:][:space:]]|[\r])+/s', "\n", $binary);
+ }
+
+ if ($min_len > 1) {
+ $min_len = min(1024, intval($min_len));
+ $binary =
+ implode("\n",
+ preg_grep('/^.{' . $min_len . ',}/S',
+ explode("\n", $binary)
+ )
+ );
+ }
+
+ return $binary;
+}
+
+