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 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波