Skip to content

Instantly share code, notes, and snippets.

@Taraflex
Created July 5, 2014 14:22
Show Gist options
  • Save Taraflex/f14cb55dd9aeac41ae1f to your computer and use it in GitHub Desktop.
Save Taraflex/f14cb55dd9aeac41ae1f to your computer and use it in GitHub Desktop.
<?php
include("SxGeo.php");
$SxGeo = new SxGeo('SxGeoCityMax.dat');
$ip = $_SERVER['REMOTE_ADDR'];
$city_info = $SxGeo->get($ip);
$city_name = "Новосибирск";
$city_name2 = "Новосибирске";
$lat = 82.92043;
$lon = 55.030199;
if($city_info && ($city_info['country']['id'] == 185)){
$city_name = $city_info['city']['name_ru'];
$lat = $city_info['city']['lat'];
$lon = $city_info['city']['lon'];
try{
$sql = mysqli_connect("localhost","u5591842_sro","srosib12345","u5591842_sro");
if (mysqli_connect_errno()) {
$sql->close();
throw new Exception("Error ", mysqli_connect_error());
}
$sql->query("SET NAMES UTF8");
$resp = $sql->query("SELECT prepositionalCase FROM `city` WHERE `name`='$city_name'");
$row = mysqli_fetch_row($resp);
$city_name2 = $row[0];
if(empty($city_name2)){
$sql->close();
throw new Exception("Error", 1);
}
}catch (Exception $e) {
try{
$padejy = new SimpleXMLElement(file_get_contents("http://export.yandex.ru/inflect.xml?name=".$city_name));
$city_name2 = $padejy->inflection[5];
}catch(Exception $e){
$city_name2 = $city_name;
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment