Reputation: 5
Excuse me for bad English. I have a table with a field called Subject . The value of this field is any kind of string. is there a way to find how many space char in per field . for example for "mme mme" is one and for "mme" is zero and for "mme mme mme" is two.
Upvotes: 0
Views: 157
Reputation: 28
If you want to do it with PHP, you can use substr_count.
substr_count(STRING_HERE, " ");
Docs to substr_count(); (PHP.NET)
It will return the number of spaces as you needed.
Upvotes: 0
Reputation: 1608
You can try this:
SELECT length(Subject) - length(replace(Subject, ' ', '')) FROM table;
Upvotes: 0
Reputation: 3332
From MySQL List:
select length(Subject) - length(replace(Subject, ' ', ''))
Or this:
SELECT CHAR_LENGTH(Subject) - CHAR_LENGTH(REPLACE(Subject, ' ', '')) as
num_spaces FROM my_table;
Upvotes: 1