<?php
set_time_limit(0);

// template for pages

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

// Create pages	
	$file_handle = fopen('countries.csv', 'r');

	while(!feof($file_handle)) 
	{
		$line 			= fgetcsv($file_handle, 1024);
		$country		= $line[0];
		$mobile			= $line[1];
		$country_file 	= 'uk-number-call-forwarding-to-'.strtolower(str_replace("- ","",str_replace(")","",str_replace("(","",str_replace(" ","-",$country))))).'.php';
		
		// Make city page
		chdir('/home/fdesign1/public_html/phone-numbers-uk.com/numbers/call-forwarding-uk-numbers/test/');
		
		if(file_exists($country_file))
		{
			unlink($country_file);
			echo $country.' original file deleted.<br>';
		}
		
		$new_content = str_replace("France",$country,$original_content);
		
		$fh = fopen($country_file,'w');
		if(fwrite($fh,$new_content))
		{
			echo $country_file.' file created.<br>';
		}
		fclose($fh);
	
	}

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