public static function Heartbeat::getWordRepeats in Heartbeat 8
Helper method to identify the number of times a word is repeated in a phrase
Parameters
$phrase:
Return value
array
1 call to Heartbeat::getWordRepeats()
- Heartbeat::handleMultipleEntities in src/
Entity/ Heartbeat.php
File
- src/
Entity/ Heartbeat.php, line 701
Class
Namespace
Drupal\heartbeat\EntityCode
public static function getWordRepeats($phrase) {
$counts = array();
$words = explode(' ', $phrase);
foreach ($words as $word) {
if (!array_key_exists($word, $counts)) {
$counts[$word] = 0;
}
$word = preg_replace("#[^a-zA-Z\\-]#", "", $word);
++$counts[$word];
}
return $counts;
}