我正在创建一个用户可以在"How are you"
之类的位置进行搜索,并将翻译结果输出到"Como son tu"
My database looks like this
English Translation
How Como
Are Son
You Tu
我的代码:
if(($_POST['translateKey'])){
$translateWord = mysql_fix_string($connection, $_POST['translateWord']);
if (!empty($translateWord)) {
$query = "SELECT * FROM $username";
$result = $connection->query($query);
if (!$result) {
if (!$result) die("Couldn't query data: " . $connection->error);
}
$rows = $result->num_rows;
$isTranslation = false;
for ($i = 0; $i < $rows; ++$i) {
$result->data_seek($i);
$row = $result->fetch_array(MYSQLI_ASSOC);
//using strpos to find the first occurrence of a substring in a string
$pos = strpos($row['English'],$translateWord);
if ($pos !== false) {
echo $row['Translation'] . "</br>";
$isTranslation = true;
break;
}
}
if (!$isTranslation)
echo "No translation can be found!</br>";
}
}
这是我的代码,但它只能搜索"How" -> "Como"
之类的单个字符,如果我尝试搜索多个字符串,它将给我"No translation can be found!"
是否可以搜索多个字符串并将字符输出为句子?像搜索"How are you"
并获得"Come son tu"
我正在出于学习目的创建一个a脚的翻译哈哈。