Created
May 18, 2024 19:43
-
-
Save hctilg/f07d83bde94a56aa3764330f0b6624ae to your computer and use it in GitHub Desktop.
This file contains 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 | |
// checking the exists Library. | |
if (!file_exists("finglish.php")) { | |
copy('https://raw.githubusercontent.com/hctilg/finglish/main/index.php', 'finglish.php'); | |
} | |
header('Access-Control-Allow-Origin: *'); | |
header('Content-Type: application/json'); | |
$response = []; | |
if (trim($_REQUEST['text'] ?? '') === '') { | |
$response['ok'] = false; | |
$response['error_code'] = 400; | |
$response['message'] = 'text is empty'; | |
} else { | |
$input = $_REQUEST['text']; | |
try { | |
$response['ok'] = true; | |
require_once('finglish.php'); | |
$model = new Finglish(); | |
$response['result'] = $model($input); | |
} catch (Exception $e) { | |
$response['ok'] = false; | |
$response['error_code'] = $e->getCode(); | |
$response['message'] = $e->getMessage(); | |
} | |
} | |
header_remove('X-Powered-By'); | |
http_response_code($response['error_code'] ?? 200); | |
echo json_encode($response, 448); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment