I would like to split a text into single words using PHP. Do you have any idea how to achieve this?
My approach:
function tokenizer($text) {
$tex
Do:
str_word_count($text, 1);
Or if you need unicode support:
function str_word_count_Helper($string, $format = 0, $search = null)
{
$result = array();
$matches = array();
if (preg_match_all('~[\p{L}\p{Mn}\p{Pd}\'\x{2019}' . preg_quote($search, '~') . ']+~u', $string, $matches) > 0)
{
$result = $matches[0];
}
if ($format == 0)
{
return count($result);
}
return $result;
}