Changes

Jump to: navigation, search

Count occurrences of a word in string

215 bytes added, 9 August
m
MySQL way
SELECT FLOOR((LENGTH(@paragraph) - LENGTH(REPLACE(@paragraph, @term, ''))) / LENGTH(@term)) AS occurrences;
 
/* same with the following query */
SELECT FLOOR((CHAR_LENGTH(@paragraph) - CHAR_LENGTH(REPLACE(@paragraph, @term, ''))) / CHAR_LENGTH(@term)) AS occurrences;
</pre>
 
[http://sqlfiddle.com/#!9/6d06f/480/2 online example]
== PHP ==

Navigation menu