简体   繁体   English

如何用PHP从数据库中计算句子的单词

[英]How to count word of sentence from database with PHP

I have a table in database我在数据库中有一张表

|ID| Sentence        |  
|1 | I have a Rabbit |     
|2 | I have a Turtle |

How to count every word in that table (or this is a TF-IDF Raw method)?如何计算该表中的每个单词(或者这是一个 TF-IDF Raw 方法)?

I  = 2 
have = 2
a = 2 
Rabbit = 1 
Turtle = 1 

Anybody help me please with PHP code?有人帮我用PHP代码吗?

You need to concat all string to a variable and then do like this您需要将所有字符串连接到一个变量,然后这样做

$words = 'Word count count';
print_r( array_count_values(str_word_count($words, 1)) );

http://sandbox.onlinephpfunctions.com/code/e7820275a94fbcf6fa814d4886167e201ce03de3 http://sandbox.onlinephpfunctions.com/code/e7820275a94fbcf6fa814d4886167e201ce03de3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM