art15 Posted April 28, 2008 Share Posted April 28, 2008 Hi, I was wondering if it is possible to count the number of words in a field. for eg if i have a field called comment and i want to count number of words in the field comment? any idea? Thanks Link to comment https://forums.phpfreaks.com/topic/103333-count-number-of-words-in-a-field/ Share on other sites More sharing options...
fenway Posted April 29, 2008 Share Posted April 29, 2008 Sadly, not really. Link to comment https://forums.phpfreaks.com/topic/103333-count-number-of-words-in-a-field/#findComment-529489 Share on other sites More sharing options...
beebum Posted April 30, 2008 Share Posted April 30, 2008 A friend of mine wrote this: http://www.kfwebs.net/news/489/How-to-count-the-number-of-occurences-in-a-string Link to comment https://forums.phpfreaks.com/topic/103333-count-number-of-words-in-a-field/#findComment-530670 Share on other sites More sharing options...
hitman6003 Posted May 1, 2008 Share Posted May 1, 2008 There is a bit of a workaround... -- essentially we are determining the number of spaces in the string (by subtracting the length -- of the string without spaces from the length with) and dividing the number of spaces into the -- total number of characters SELECT LENGTH(column_name) / (LENGTH(column_name) - LENGTH(REPLACE(column_name, ' ', ''))) AS num_of_words FROM table_name It's not 100% accurate, but it'll pass. Link to comment https://forums.phpfreaks.com/topic/103333-count-number-of-words-in-a-field/#findComment-530799 Share on other sites More sharing options...
fenway Posted May 1, 2008 Share Posted May 1, 2008 Not a bad approximation. Link to comment https://forums.phpfreaks.com/topic/103333-count-number-of-words-in-a-field/#findComment-531075 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.