2014-03-06 26 views
0

我列出的這個awstat文件中的國家代碼和多少人訪問和點擊:變化和顯示元件

# Domain - Pages - Hits - Bandwidth 
BEGIN_DOMAIN 1 
ua 245 245 970690 
us 90 647 10311747 
cn 27 27 106974 
ru 25 26 99953 
gb 12 82 1155179 
fr 7 7 41230 
kr 4 4 15848 
de 4 15 211641 
in 3 15 234340 
ph 2 2 7924 
lv 2 2 0 
ro 2 2 13856 
il 1 1 3962 
dk 1 1 3962 
vn 1 1 3962 
nl 1 1 3962 
lt 1 1 3962 
ca 0 1 20264 
END_DOMAIN 

我試圖提取它,並通過國家的頁面農佈雷顯示它每個國家,所以我想這:

preg_match("/BEGIN_DOMAIN(.*)END_DOMAIN/is", $awstats, $matches); 
$country = $matches[0] ; 
awstats_extract_country($country) ; 

它調用函數awstats_extract_country($country)

function awstats_extract_country($country) 
{ 
    $country = explode("\n", $country) ; 
    unset($country[(count($country)-1)]) ; 
    unset($country[0]) ; 
    foreach ($country as $key => $value) 
    $country[$key] = explode(" ", $value) ; 

    //print_array($sider); 
    $fields = array(

     0 => "Country" , 
     1 => "Pages" , 
     2 => "Hits" , 
     3 => "Bandwidth" , 
    ) ; 
    echo '<div id="collapse_awstats_extract_sider" class="accordion-body collapse in">'; 
     echo '<div class="accordion-inner">'; 
      print_table($country, $fields); 
     echo '</div>'; 
    echo '</div>'; 
} 

但它顯示我的國家縮寫,就像在文件中有沒有辦法可以讓他們在國家的名字,我的意思是ua ==>UKRAINE等等,就像這裏http://www.iso.org/iso/fr/french_country_names_and_code_elements.htm

非常感謝

+2

我認爲,這可能是有用的:http:/ /stackoverflow.com/questions/12143252/convert-country-name-to-country-code-abbreviations-php或http://snipplr.com/view/36868/ – Flixer

回答