dongyipa0028 2014-10-25 02:16
浏览 56
已采纳

使用PHP搜索存储在文件中的大量单词列表的最快方法

I have a text file that contains safe words. I want to be able to check user inputs which arrive as large strings (50-100 words) to make sure that they only contain safe words. I am wondering what is the right approach to do this in PHP.

The only approach I have in mind is looping through user's response word by word and compare against the list of safe words. This approach, unfortunately, leads to memory size issues!

The file that contains the safe words has well over 700K words.

  • 写回答

1条回答 默认 最新

  • doumi9661 2014-10-25 03:33
    关注

    you can try following code to convert file content in array. then you can use isset or in_array for further operations.

    <?php    
    $file = file_get_contents('test.txt');       
    $arr=array_combine(explode(' ',$homepage));    
    $final_arr=array_combine($arr,$arr);    
    print_r($final_arr);    
    ?>    
    

    hope this can help you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口