Say I had the following:
$name= "albert slevir inshten";
For the above, I would get 3.
PHP provides a function called substr_countthat counts the number of occurrences of a substring:
substr_count
$count = substr_count($str, ' '); //2
To get the word count, you should use str_word_count:
str_word_count
$count = str_word_count($str); //3
to count substring entries, use: substr_count()
substr_count()
to count the number of words, use: str_word_count()
str_word_count()
see count_chars () .
I think there are only 2 spaces in this example ...
Offering the following:
$no = count(explode(" ",$str))-1;
You can leave -1 if you want to know the number of words (for example, 3 in your example)
PHP has a function called substr_count(), you can use it like this:
$name= "albert slevir inshten"; echo substr_count($name, ' ');
Source: https://habr.com/ru/post/1786495/More articles:What does it mean "Failed to initialize com.ibm.icu.impl.JavaTimeZone class"? - androidHow to list all the artists in a rhythm box plugin - pythonUnder what circumstances will GetClipboardData (CF_TEXT) return NULL? - clipboardHTML / CSS layout help in IE - htmlОграничение командной строки PHP cli safe_mode - command-line-interfaceStandalone RedCloth on Windows - windowsRuby DevKit does not work for RedCloth and other stones on WindowsXP - ruby-on-railsdatabase - smooth and normalized - databaseDifference between Satchmo local_settings.py and settings.py - pythonAjax views with django - ajaxAll Articles