<?php
// top of page

    $top_content = "";
    $fh1 = fopen('top.php','r');
    while(!feof($fh1))
    {
        $top_content .= fgets($fh1);
    }
    fclose($fh1);
    
// bottom of page

    $bot_content = "";
    $fh2 = fopen('bottom.php','r');
    while(!feof($fh2))
    {
        $bot_content .= fgets($fh2);
    }
    fclose($fh2);

    
// Create pages 
    $file_handle = fopen('separate-regions.csv', 'r');
    $list_content = "";

    while(!feof($file_handle)) 
    {
        $line = fgetcsv($file_handle, 1024);
        $city   = $line[0];
        $code   = $line[1];
        $city_all = $line[2];
        $city_link = '0'.$code.'-numbers-'.strtolower(str_replace("- ","",str_replace(")","",str_replace("(","",str_replace(" ","-",$city))))).'.html';
        $add_line = '<li><a href="'.$city_link.'" title="Get '.$city.' '.$code.' Numbers">'.$city_all.'</a></li>';
        
        $list_content .= $add_line."\n";     
    }
    fclose($file_handle);
    
    $full_content = $top_content.$list_content.$bot_content;
    $citylist_file = '/var/www/vhosts/phone-numbers-uk.com/httpdocs/geographic-numbers/uk-regional-numbers.php';
    
    if ($handle_city = fopen($citylist_file,'w'))
    {
        fwrite($handle_city,$full_content);
        fclose($handle_city);
    }
    echo 'Done';
?>