Created
January 3, 2016 21:25
-
-
Save riza/f29e9364e8cbe0f341b1 to your computer and use it in GitHub Desktop.
yaşasın isteğe bağlı spagetti
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function file_get_contents_utf8($fn) { | |
| $content = file_get_contents($fn); | |
| return mb_convert_encoding($content, 'UTF-8', | |
| mb_detect_encoding($content, 'UTF-8, ISO-8859-9', true)); | |
| } | |
| $count = 0; | |
| $okul = array(); | |
| set_time_limit(1800); | |
| for ($ilce=1; $ilce <= 41; $ilce++) { | |
| $url = "http://www.meb.gov.tr/baglantilar/okullar/index.php?ILKODU=34&ILCEKODU=".$ilce; | |
| $get = file_get_contents_utf8($url); | |
| $patterns = [ | |
| "okul" => "/<td><a href=\"(.+?)\" target=\"_blank\">(.+?) - (.+?) - (.+?)<\/a><\/td>/", | |
| "son_sayfa" => "/<a href=\"?(.*?)\" class=\"last\" title=\"Son Sayfa\"><span>>><\/span><\/a>/" | |
| ]; | |
| //preg_match_all($patterns["okul"], $get, $output_array); | |
| preg_match_all($patterns["son_sayfa"], $get, $sonsayfa); | |
| $sayfa_parcala =explode("=",$sonsayfa[1][0]); | |
| $sayfa_sayisi = $sayfa_parcala[3]; | |
| if ($sayfa_sayisi <= 1) { | |
| $url = "http://www.meb.gov.tr/baglantilar/okullar/index.php?ILKODU=34&ILCEKODU=".$ilce."&SAYFANO=".$sayfa_sayisi; | |
| $get = file_get_contents_utf8($url); | |
| preg_match_all($patterns["okul"], $get, $output_array); | |
| foreach ($output_array[4] as $school => $key) { | |
| //echo strtoupper($key)."<br>"; | |
| //echo $output_array[3][$school]; | |
| array_push($okul,array( | |
| 'county' => $output_array[3][$school], | |
| 'school_name' => $key)); | |
| $count++; | |
| } | |
| } else { | |
| for ($i=1; $i <= $sayfa_sayisi; $i++) { | |
| $url = "http://www.meb.gov.tr/baglantilar/okullar/index.php?ILKODU=34&ILCEKODU=".$ilce."&SAYFANO=".$i; | |
| $get = file_get_contents_utf8($url); | |
| preg_match_all($patterns["okul"], $get, $output_array); | |
| foreach ($output_array[4] as $school => $key) { | |
| array_push($okul,array( | |
| 'county' => $output_array[3][$school], | |
| 'school_name' => $key)); | |
| $count++; | |
| } | |
| } | |
| } | |
| } | |
| foreach ($okul as $school) { | |
| echo "INSERT INTO school_names ('county', 'school_name') VALUES ('".$school["county"]."', '".$school["school_name"]."');<br>"; | |
| } | |
| echo "<br>Toplam : ".$count; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment