I'd like to use the API to create something that finds typographical errors, but I'm stuck, so I'd like to ask you a question.
For the time being, I would like to make sure that there are no errors now.
Messages displayed:
Warning:Trying to access array offset on value of type null in C:\xampp\htdocs\graduation\sotoken.php on line 24
Current State Code:
<?php
$post_flag=false;
if($_SERVER["REQUEST_METHOD"] === "POST") {
$post_flag=true;
$url="https://api.a3rt.recruit-tech.co.jp/proofreading/v2/typo";
$apikey="xxxxxxxxxx";
$sentence=str_replace(array("\r\n", "\r", "\n", "", "", "", "", "@$_POST['text']); // Input Sentences
$sensitivity=@$_POST ['sensitivity']; // Check sensitivity (low, medium, high)
$postdata=array(
"apikey" = > $apikey,
"sentence" = > $sentence,
"sensitivity" = > $sensitivity
);
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postdata);
$curl=curl_exec($ch);
curl_close($ch);
$results=json_decode($curl, true);
$alerts=@$results["alerts"]?:';
// Prevent Cross-Site Scripting (XSS) Vulnerability
$checked_sentence=htmlspecialchars($results['checkedSentence',ENT_QUOTES);
$checked_sentence=str_replace(array('&&'), '<span class="error">', $checked_sentence);
$checked_sentence=str_replace(array('>&'), '</span>', $checked_sentence);
function get_alert_text($score){
$text=';
if($score>0.7){
$text = "Possibility of typographical errors: large";
}
elseif($score>0.3){
$text = "Possible typo: Medium";
}
else{
$text = "Possibility of typo: small";
}
return$text;
}
$status_code=array(
"0" = > "Normal response (not specified),
"1" = > "Normal response (indicated),
"1000" = > "API Key Unspecified",
"1001" = > "API Key Not Found",
"1002" = > "Departed",
"1003" = > "Account Not Approved",
"1010" = > "Server Not Found",
"1011" = > "Server Configuration Error",
"1030" = > "Access Denied",
"1400" = > "Request parameter is invalid",
"1400" = > "Request parameter is incorrect (sentence is not UTF-8)",
"1404" = > "The specified object cannot be found",
"1405" = > "Incorrect Method",
"1413" = > "Request parameter value is too long",
"1500" = > "An unexpected error occurs during server processing",
);
}
?>
<!DOCTYPE HTML>
<html lang="ja">
<head>
<metacharset="utf-8">
<title> PHP Sample</title>
</head>
<body>
<form action="sotaken.php" method="post">
<p>Input area: <br>
<input type="text" name="text">/p>
<p><input type="submit" value="send">/p>
</form>
</body>
</html>
Warning:Trying to access array offset on value of type null
displays a warning when accessing variables that are not arrays as arrays.(for example, variables of "null" or "numerical" type)
json_decode with $results array returns null if passed.
Therefore, I think curl's communication result is null.
P.S. I think it is better to investigate the cause one by one without suppressing the warning display by adding @.
© 2024 OneMinuteCode. All rights reserved.