<?php
set_time_limit(0);

// template for pages

	$original_content = "";
	$fh1 = fopen('template.php','r');
	while(!feof($fh1))
	{
		$original_content .= fgets($fh1);
	}
	fclose($fh1);

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

	while(!feof($file_handle)) 
	{
		$line 		= fgetcsv($file_handle, 1024);
		$city 		= $line[0];
		$code		= $line[1];
		$city_text	= $line[2];
		$city_file 	= '0'.$code.'-'.strtolower(str_replace("- ","",str_replace(")","",str_replace("(","",str_replace(" ","-",$city))))).'-uk-numbers.php';
		
		// Make city page
		chdir('/home/fdesign1/public_html/phone-numbers-uk.com/numbers/');
		
		if(file_exists($city_file))
		{
			unlink($city_file);
			echo $city_text.' original file deleted.<br>';
		}
		
		$new_content = str_replace("1200",$code,str_replace("Clitheroe",$city,$original_content));
		
		$fh = fopen($city_file,'w');
		if(fwrite($fh,$new_content))
		{
			echo $city_file.' file created.<br>';
		}
		fclose($fh);
	
	}

	fclose($file_handle);
	echo '<br><b>All Files have been updated.</b>';
?>