[ 'city' => 'Hà Nội', 'region' => 'Miền Bắc', 'temperature' => 26, 'feels_like' => 28, 'humidity' => 74, 'wind_speed' => 14, 'condition' => 'Trời mát, có mây rải rác', 'icon' => '⛅', 'uv_index' => 5 ], 'tp.hcm' => [ 'city' => 'TP. Hồ Chí Minh', 'region' => 'Miền Nam', 'temperature' => 33, 'feels_like' => 36, 'humidity' => 65, 'wind_speed' => 18, 'condition' => 'Nắng ấm, chiều tối có mưa rào nhẹ', 'icon' => '🌤️', 'uv_index' => 8 ], 'da nang' => [ 'city' => 'Đà Nẵng', 'region' => 'Miền Trung', 'temperature' => 29, 'feels_like' => 31, 'humidity' => 70, 'wind_speed' => 22, 'condition' => 'Trời nắng đẹp, gió biển nhẹ', 'icon' => '☀️', 'uv_index' => 7 ], 'hue' => [ 'city' => 'Huế', 'region' => 'Miền Trung', 'temperature' => 25, 'feels_like' => 26, 'humidity' => 84, 'wind_speed' => 12, 'condition' => 'Mưa phùn nhẹ, tiết trời dịu mát', 'icon' => '🌧️', 'uv_index' => 4 ], 'da lat' => [ 'city' => 'Đà Lạt', 'region' => 'Tây Nguyên', 'temperature' => 18, 'feels_like' => 17, 'humidity' => 88, 'wind_speed' => 10, 'condition' => 'Se lạnh, có sương mù buổi sớm', 'icon' => '🌫️', 'uv_index' => 3 ], 'can tho' => [ 'city' => 'Cần Thơ', 'region' => 'Đồng bằng Sông Cửu Long', 'temperature' => 31, 'feels_like' => 34, 'humidity' => 72, 'wind_speed' => 15, 'condition' => 'Nắng dịu, mây thay đổi', 'icon' => '⛅', 'uv_index' => 7 ], 'hai phong' => [ 'city' => 'Hải Phòng', 'region' => 'Miền Bắc', 'temperature' => 25, 'feels_like' => 27, 'humidity' => 78, 'wind_speed' => 20, 'condition' => 'Nhiều mây, gió mát từ biển', 'icon' => '☁️', 'uv_index' => 5 ] ]; function removeVietnameseAccents(string $str): string { $accents = [ 'a' => '/[àáạảãâầấậẩẫăằắặẳẵ]/u', 'e' => '/[èéẹẻẽêềếệểễ]/u', 'i' => '/[ìíịỉĩ]/u', 'o' => '/[òóọỏõôồốộổỗơờớợởỡ]/u', 'u' => '/[ùúụủũưừứựửữ]/u', 'y' => '/[ỳýỵỷỹ]/u', 'd' => '/[đ]/u', ]; $str = mb_strtolower($str, 'UTF-8'); foreach ($accents as $nonAccent => $regex) { $str = preg_replace($regex, $nonAccent, $str); } return trim($str); } $normalized = removeVietnameseAccents($cityInput); if (in_array($normalized, ['ho chi minh', 'tphcm', 'tp. ho chi minh', 'sai gon'], true)) { $normalized = 'tp.hcm'; } if (isset($weatherDatabase[$normalized])) { $data = $weatherDatabase[$normalized]; } else { // Tạo dữ liệu giả lập ổn định theo tên thành phố bất kỳ $hash = crc32($normalized); $temp = 20 + ($hash % 15); $humidity = 60 + ($hash % 30); $wind = 8 + ($hash % 20); $data = [ 'city' => $cityInput ?: 'Không xác định', 'region' => 'Việt Nam / Quốc tế', 'temperature' => $temp, 'feels_like' => $temp + 2, 'humidity' => $humidity, 'wind_speed' => $wind, 'condition' => 'Thời tiết ổn định, mây thay đổi', 'icon' => '🌤️', 'uv_index' => 6 ]; } $data['status'] = 'success'; $data['updated_at'] = date('H:i:s d/m/Y'); echo json_encode($data, JSON_UNESCAPED_UNICODE);