<?php
error_reporting(-1);
mb_internal_encoding('utf-8');

$text = <<<EOF
Это - хорошо
EOF;

$text = mb_strtolower($text);
$words = [];
$wordFounder = "/[\p{L}\-\_]+/ui";
$count = preg_match_all($wordFounder, $text, $pregResult);
$result = [];
$words = $pregResult[0];
$result = array_count_values($words);
arsort($result);
	
echo "Всего слов в тексте - $count.\n";

foreach ($result as $word => $count) {
	echo "$word - встречается $count раз.\n";
}

