Java php find similar words
<p>Okay, so my app will find the word you type into the text box from a database inside my website.. and it will find the "word" if there is more than 1 "word" it will go through each and pick a random "reply"</p>

<p>How can I do it so that if it can't find the word "hey" it will look for similar things like "he" etc?</p>

<p>Here's my PHP:</p>

<pre><code>    &lt;?php
// Connect to database
mysql_connect("server", "db username", "db password");
mysql_select_db("db405677000");

// If something is received
if($_POST)
{
    if($_POST['action'] == "ask")
    {
        // Filter it to prevent SQL injections
        $text = mysql_real_escape_string($_POST['stringdata']);

        // Search it on the database
        $q = mysql_query("SELECT `reply` FROM `poka` WHERE `word` = '$text' ORDER BY RAND()");

        // Show result
        if($r = mysql_fetch_assoc($q))
            echo $r['reply'];
        else
            echo "Cannot find a reply";
    }
    elseif($_POST['action'] == "teach")
    {
        // Filter it to prevent SQL injections
        $word = mysql_real_escape_string($_POST['word']);
        $answer = mysql_real_escape_string($_POST['answer']);

        // Insert it to the database
        if( mysql_query("INSERT INTO `poka` VALUES(NULL, '$word', '$answer')") )
            echo "ok";
        else
            echo "fail";
    }
}
?&gt;
</code></pre>

<p>And here is my java part where it actually gets the response:</p>

<pre><code>public void responseGet(String textRequest)
{
    EditText textbox = (EditText)findViewById(R.id.chat);
    textbox.setText("");

    TableLayout chatbox = (TableLayout)findViewById(R.id.chatbox);
    if(canReply == false)
    {
        TableRow tr1 = new TableRow(this);
        tr1.setLayoutParams(new LayoutParams( LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
        TextView textview = new TextView(this);

        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://monaiz.net/get.php");

        String responseStr = "";

        try {
            // Add your data
            List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2);
            nameValuePairs.add(new BasicNameValuePair("stringdata", textRequest));
            nameValuePairs.add(new BasicNameValuePair("action", "ask"));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity( );

            responseStr = EntityUtils.toString( entity ).replace("\\", "");

        } catch (Exception e) {
            // TODO Auto-generated catch block
        }

        textview.setText(responseStr);
      //  textview.getTextColors(R.color.)
        textview.setTextColor(Color.BLACK);
        textview.setGravity(Gravity.LEFT);

         tr1.addView(textview);

      // Convert dp to px
            int padding_in_dp = 7;
            final float scale = getResources().getDisplayMetrics().density;
            int padding_in_px = (int) (padding_in_dp * scale + 0.5f);

            tr1.setPadding(padding_in_px, 0, padding_in_px, 0);
         tr1.setBackgroundResource(R.drawable.pokaspeak);

         tr1.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent startNewActivityOpen = new Intent(main.this, TeachmeDialog.class);
                    startActivityForResult(startNewActivityOpen, 0);
                }
              });

            chatbox.addView(tr1, new TableLayout.LayoutParams(
                    LayoutParams.FILL_PARENT,
                   LayoutParams.WRAP_CONTENT));
           canReply = true;


           new Handler().postDelayed(new Runnable() {
               @Override
               public void run() {
                ScrollView s = (ScrollView) findViewById(R.id.SV);
                s.fullScroll(View.FOCUS_DOWN);
               }
           },100);
    }
}
</code></pre>
