From b24622e2d1bbcd3aa5d3568412784b0c82f2327f Mon Sep 17 00:00:00 2001 From: Robert Nelson Date: Wed, 6 Nov 2013 22:54:02 -0800 Subject: Rewrite the display_host_results() function to use spaces instead of tabs. It does a much better job of aligning the fields in each column and works in all the browsers, particularly chrome which doesn't support the tab character. It still isn't perfect due to the javascript alert() function's use of a proportional font. --- usr/local/www/diag_dns.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/usr/local/www/diag_dns.php b/usr/local/www/diag_dns.php index 6b336a2..b737477 100644 --- a/usr/local/www/diag_dns.php +++ b/usr/local/www/diag_dns.php @@ -150,15 +150,24 @@ if( ($_POST['host']) && ($_POST['dialog_output']) ) { } function display_host_results ($address,$hostname,$dns_speeds) { + $map_lengths = function($element) { return array(strlen($element[0]), strlen($element[1])); }; + $map_column0 = function($element) { return $element[0]; }; + echo gettext("IP Address") . ": {$address} \n"; echo gettext("Host Name") . ": {$hostname} \n"; echo "\n"; - echo gettext("Server") . "\t" . gettext("Query Time") . "\n"; - if(is_array($dns_speeds)) - foreach($dns_speeds as $qt){ - echo trim($qt['dns_server']) . "\t" . trim($qt['query_time']); - echo "\n"; + $text_table = array(); + $text_table[] = array(gettext("Server"), gettext("Query Time")); + if (is_array($dns_speeds)) { + foreach ($dns_speeds as $qt) { + $text_table[] = array(trim($qt['dns_server']), trim($qt['query_time'])); } + } + $length_table = array_map($map_lengths, $text_table); + $col0_padlength = max(array_map($map_column0, $length_table)); + foreach ($text_table as $text_row) { + echo str_pad($text_row[0], $col0_padlength + 4) . $text_row[1] . "\n"; + } } include("head.inc"); ?> -- cgit v1.1 From 84eaea96c6d38d11f4ea7531f341122fd34b3906 Mon Sep 17 00:00:00 2001 From: Robert Nelson Date: Thu, 7 Nov 2013 00:34:39 -0800 Subject: Simplify the code. No need to worry about the second column, we only need to pad the first one. --- usr/local/www/diag_dns.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/usr/local/www/diag_dns.php b/usr/local/www/diag_dns.php index b737477..98271d1 100644 --- a/usr/local/www/diag_dns.php +++ b/usr/local/www/diag_dns.php @@ -150,8 +150,7 @@ if( ($_POST['host']) && ($_POST['dialog_output']) ) { } function display_host_results ($address,$hostname,$dns_speeds) { - $map_lengths = function($element) { return array(strlen($element[0]), strlen($element[1])); }; - $map_column0 = function($element) { return $element[0]; }; + $map_lengths = function($element) { return strlen($element[0]); }; echo gettext("IP Address") . ": {$address} \n"; echo gettext("Host Name") . ": {$hostname} \n"; @@ -163,10 +162,9 @@ function display_host_results ($address,$hostname,$dns_speeds) { $text_table[] = array(trim($qt['dns_server']), trim($qt['query_time'])); } } - $length_table = array_map($map_lengths, $text_table); - $col0_padlength = max(array_map($map_column0, $length_table)); + $col0_padlength = max(array_map($map_lengths, $text_table)) + 4; foreach ($text_table as $text_row) { - echo str_pad($text_row[0], $col0_padlength + 4) . $text_row[1] . "\n"; + echo str_pad($text_row[0], $col0_padlength) . $text_row[1] . "\n"; } } -- cgit v1.1