<?
$arr=file("province.txt");// the txt file to be read
// read the data from province.txt and write into 02_district.yml
$myFile = "02_district.yml";
//open a new file with name $myFile, if permission is dennied, throws message
$fh = fopen($myFile, 'w') or die("can't open file");
// write the head in YML file without backspace
$head= "District:\n";
fwrite($fh, $head);
$i = 0;
$k = 0;
$tmp = "province";
foreach($arr as $str)
{
$k++;
// split $str, if digits were found
list($province,$district)=preg_split("/[\d]+/", $str);;
/*echo "<ul>";
echo "<li>".$province;
echo "<li>".$district;
echo "</ul>";
echo "<hr>";*/
$district_id = " District_".$k.":\n";// \n change line
$district_name = " name: ".$district."";
if($tmp != $province){//if province is changed, increase the id of province
$i++;
$tmp = $province;
}
$province_id = " province_id: Province_".$i."\n";
fwrite($fh, $district_id);//write the value in file
fwrite($fh, $district_name);
fwrite($fh, $province_id);
}
fclose($fh);
?>
// this is text file to be read by PHP script
Nuristan 3001 Nuristan
Nuristan 3002 Kamdesh
Nuristan 3003 Waygal
Nuristan 3004 Mandol
Nuristan 3005 Bargi Matal
Nuristan 3006 Wama
Nuristan 3007 Du Ab
Nuristan 3008 Nurgaram
Sari Pul 3101 Sari Pul
Sari Pul 3102 Sangcharak
Sari Pul 3103 Kohistanat
Sari Pul 3104 Balkhab
Sari Pul 3105 Sozma Qala
Sari Pul 3106 Sayyad
Sari Pul 3107 Gosfandi
php
1
<?$arr=file("province.txt");// the txt file to be read// read the data from province.txt and write into 02_district.yml$myFile="02_district.yml";//open a new file with name $myFile, if permission is dennied, throws message$fh=fopen($myFile,'w')ordie("can't open file");// write the head in YML file without backspace$head="District:\n";fwrite($fh,$head);$i=0;$k=0;$tmp="province";foreach($arras$str){$k++;// split $str, if digits were foundlist($province,$district)=preg_split("/[\d]+/",$str);;/*echo "<ul>"; echo "<li>".$province; echo "<li>".$district; echo "</ul>"; echo "<hr>";*/$district_id=" District_".$k.":\n";// \n change line$district_name=" name: ".$district."";if($tmp!=$province){//if province is changed, increase the id of province$i++;$tmp=$province;}$province_id=" province_id: Province_".$i."\n";fwrite($fh,$district_id);//write the value in filefwrite($fh,$district_name);fwrite($fh,$province_id);}fclose($fh);?>// this is text file to be read by PHP scriptNuristan 3001 NuristanNuristan 3002 KamdeshNuristan 3003 WaygalNuristan 3004 MandolNuristan 3005 Bargi MatalNuristan 3006 WamaNuristan 3007 Du AbNuristan 3008 NurgaramSari Pul 3101 Sari PulSari Pul 3102 SangcharakSari Pul 3103 KohistanatSari Pul 3104 BalkhabSari Pul 3105 Sozma QalaSari Pul 3106 SayyadSari Pul 3107 Gosfandi
Hey there! I see you're running Internet Explorer 6.
That's neat. This reminds me of my grandpa. He had this old car that he kept having to fix. He spent so much money on it that he didn't want to get rid of it (even when it stopped running).
0 Comments