Count occurrences of a word in string: Difference between revisions

Jump to navigation Jump to search
m
(+ PHP)
Line 14: Line 14:


== PHP ==
== PHP ==
Using the [https://www.php.net/manual/en/function.mb-substr-count.php mb_substr_count] ('''binary safe''') or [https://www.php.net/manual/en/function.substr-count.php substr_count] function
Using the [https://www.php.net/manual/en/function.mb-substr-count.php mb_substr_count] ('''binary safe''') or [https://www.php.net/manual/en/function.substr-count.php substr_count] functions. See details on [http://sandbox.onlinephpfunctions.com/code/326ff9f24ebfea9f67ddf2f1475a6172cdcd2e66 demo].
 
 
<pre>
$input = 'an apple a day keeps the doctor away';
$term = 'apple';
 
echo substr_count($input, $term);
</pre>


[[Category:Software]] [[Category:Programming]] [[Category:Data Science]] [[Category:Text file processing]]
[[Category:Software]] [[Category:Programming]] [[Category:Data Science]] [[Category:Text file processing]]

Navigation menu