dsn1327 2012-07-24 06:14
浏览 70
已采纳

anagram finder program php mysql

i am trying to write a program for anagram finder in php mysql.. i have dictionary in database which has only one field named 'word' and it contains 500000 rows.

by using php i tried to pull words one by one from database.. After getting a word i created 2 for loops which performs character by character comparison..

for example.. let the input word be 'abcdef'..

consider i am fetching the word 'fade' from database..

i am writing a loop and checking whether the word fade is in abcdef .. if yes i am printing the word.. if not, i will fetch next word from database..

i wrote the code.. but i am getting an empty page as output.. pls help..

i have one more question. is there any other way to find the substring of a word without using character by character comparison?

for example : if my input is fedcba.. i sort it as abcdef.. and dictionary word is fade and i sort it as adef.. is thr any function to find whether adef is a substring of abcdef..

  • 写回答

2条回答 默认 最新

  • doujia1904 2012-07-24 06:19
    关注

    Forget checking each word in PHP. That's a CPU nightmare!

    Add a second column to your table, and have the word spelled out in alphabetical order. For example:

    Word : AlphaWord
    Test : estt
    

    Then you can simple run a query like this:

    select word from table 1 where AlphaWord = (select AlphaWord from table1 where word='$yourWord') order by word asc;
    

    Edit: If you didn't want to match words within other words, you could pop a Fulltext search index on the AlphaWord column and then use the Match()... against() syntax which will return the matches very fast. However, as this operator would only allow for a wildcard to be placed on the end of a search string, it won't match machete->aceehmt with ache->aceh. Having said that, to be honest, you couldn't really add in a wildcard in a normal search either that would match them.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog