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条)

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路