简体   繁体   English

自动更正Web应用程序中的拼写错误

[英]Auto correct spelling errors in web application

I develop web application i have search engine in it . 我开发了具有搜索引擎的Web应用程序。 I read the data from database . 我从数据库读取数据。 I built the search engine that can help to complete the word, but need to help to correct the spelling such as i write spelling this word is wrong i want to help and find the correct word such as do you mean spelling such as in Google search engine . 我建立了可以帮助完成单词的搜索引擎,但是需要帮助纠正拼写,例如我写的单词拼写错误。我想帮助并找到正确的单词,例如您在谷歌搜索中表示的意思是拼写引擎。 help please I saw many links and can't find the right solution. 请帮忙,我看到了很多链接,但找不到正确的解决方案。

 <h2>Search</h2> 
  <form name="search" method="post" action="<?=$PHP_SELF?>">
  Seach for: <input type="text" name="find" /> in 
  <Select NAME="field">
  <Option VALUE="fname">diseasename</option>
  <Option VALUE="lname">genename</option>
  </Select>
  <input type="hidden" name="searching" value="yes" />
  <input type="submit" name="search" value="Search" />
  </form>
  </html>
  <?php 
  //This is only displayed if they have submitted the form 
  if ($searching =="yes") 
  { 
  echo "<h2>Results</h2><p>"; 

  //If they did not enter a search term we give them an error 
  if ($find == "") 
  { 
  echo "<p>You forgot to enter a search term"; 
  exit; 
  } 

You could use jQuery keypress in the input text that you want to spell check. 您可以在要拼写检查的输入文本中使用jQuery 按键 Then using .ajax send the value from the input text to the server and check if the value received it's similar to anything that you have in your database. 然后使用.ajax将值从输入文本发送到服务器,并检查接收到的值是否与数据库中的值相似。 Here is a similar question regarding this last part. 关于这最后一部分,这是一个类似的问题

So in general you do this in the html 所以一般来说,您可以在html中执行此操作

<h2>Search</h2> 
<form name="search" method="post" action="<?=$PHP_SELF?>">
Seach for: <input type="text" name="find" id="find" /> in 
<Select NAME="field">
<Option VALUE="fname">diseasename</option>
<Option VALUE="lname">genename</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>
</html>

<script>
  $( "#search" ).keypress(function(event) {
      var value = $(this).val();
      $.ajax({
           type:"POST" // or GET ,
           url: "search.php", // the url to the php file
           data: {value:value}, //send the value
           success:function( msg){
                //update your input text to indicate if you have an error
           },

      });
  });

<script>

And in the php you need to do something with this value. 在php中,您需要使用此值来做一些事情。 Depending what you want to do. 根据您想做什么。 If you want to show suggestion then it's something like the link I put before (this) . 如果您想显示建议,则类似于我在(this)之前放置的链接。 But if you only want to check if the word exists then it's only something like this: 但是,如果您只想检查单词是否存在,那么它就是这样:

 <?php
  //some code
  $value = $_POST['value'];
  //connect to the data base and make stuff to prevent sql injection      
  $sql = "SELECT name FROM myTable WHERE name = '".$value."'"; //this is just an example
  ?>

Of course this is an extremely simple example. 当然,这是一个非常简单的示例。 You could use LIKE operator or more complex stuff 您可以使用LIKE运算符或更复杂的东西

Hope it helps 希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM