douyuben9434 2010-06-10 10:36
浏览 24
已采纳

如何从PHP中存储在我的数据库中的文本中获取前n个单词?

I need to know how to get the first n words from text stored in my DB in PHP?

for example if there is some text in my DB like this one :

"word1 word2 word3 word4 text one test four five"

How I can get the first 4 or five words from this text?

  • 写回答

3条回答 默认 最新

  • doumi7861 2010-06-10 10:39
    关注

    You can use the explode function to split the string by space and get each word:

    $words = 'word1 word2 word3 word4 text one test four five';
    $words_array = explode(' ', $words);
    

    And then you can use the array_chunk function to get number of words:

    print_r(array_chunk($words_array, 4, true));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi