From: henoheno Date: Sun, 17 Jun 2007 15:11:24 +0000 (+0900) Subject: whois_responsibility() simplifies them all X-Git-Url: http://git.osdn.net/view?p=pukiwiki%2Fpukiwiki_sandbox.git;a=commitdiff_plain;h=22cf4d3726c427c921859483d033ba74e1279307 whois_responsibility() simplifies them all --- diff --git a/spam/spam.php b/spam/spam.php index 294306e..4a6ea34 100644 --- a/spam/spam.php +++ b/spam/spam.php @@ -1,5 +1,5 @@ array($rest => NULL)) ); } + ksort_by_domain($trie); - // Sort and flatten -- 'A.foo.bar.example.com, B.foo.bar.example.com' + $result = array(); foreach(array_keys($trie) as $key) { - if (is_array($trie[$key])) { - ksort_by_domain($trie[$key]); - $trie[$key] = implode(', ', array_flat_leaves($trie[$key])); - //$trie[$key] = var_export($trie[$key], TRUE); // DEBUG - } - } - - ksort_by_domain($trie); + // Sort and flatten -- 'A.foo.bar., B.foo.bar.' + ksort_by_domain($trie[$key]); + $trie[$key] = implode(', ', array_keys($trie[$key])); - // Format: From array('foobar' => 'foobar') to 'foobar' - $tmp = array(); - foreach($trie as $key => $value) { - if ($trie[$key] == $key) { - // 'responsibility.example.com' - $tmp[] = ' \'' . $key . '\','; + // Format: var_export_shrink() -like output + if ($trie[$key] == '.') { + // Just one 'responsibility.example.com' + $result[] = ' \'' . $key . '\','; } else { - // 'subdomain-or-host.responsibility.example.com' - $tmp[] = ' \'.' . $key . '\' => \'' . $trie[$key] . '\','; + // One subdomain-or-host, or several ones + $result[] = ' \'' . $key . '\' => \'' . $trie[$key] . '\','; } + unset($trie[$key]); } - return 'array (' . "\n" . implode("\n", $tmp) . "\n" . ')'; + return + 'array (' . "\n" . + implode("\n", $result) . "\n" . + ')'; } // ksort() by domain