duankang5285 2016-10-07 12:53
浏览 30
已采纳

PHP:用* [关闭]替换.txt文件中列表中的单词

I've searched around the web for days now, and I can't get an answer for my problem...

So this is what I need to do:
I have an .txt-file which contains one word per line. Let's say it's called list.txt.
And I have another .txt-file called text.txt with random stuff in it.
Now I want to have a PHP-file which checks if it finds words from list.txt in the text.txt-file and replace them with ******.


THANK YOU VERY MUCH FOR ANY HELP!

  • 写回答

2条回答 默认 最新

  • dongmo1708 2016-10-07 13:02
    关注

    Consider this as a kind of pseudocode, although it's PHP. It should guide you for your desired solution:

    $content = file_get_contents('text.txt');
    $censored = explode("
    ", file_get_contents('list.txt'));
    $content = str_replace($censored, '*****', $content);
    file_put_contents('text.txt', $content);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)