//ads:
?>
str_word_count() function doesn't display Arabic language properly
PHP Snippet 1:
if (!function_exists('mb_str_word_count'))
{
function mb_str_word_count($string, $format = 0, $charlist = '[]') {
$string=trim($string);
if(empty($string))
$words = array();
else
$words = preg_split('~[^\p{L}\p{N}\']+~u',$string);
switch ($format) {
case 0:
return count($words);
break;
case 1:
case 2:
return $words;
break;
default:
return $words;
break;
}
}
}
PHP Snippet 2:
substr_count($text, ' ') + 1;
PHP Snippet 3:
public function customWordCount($content_text)
{
$resultArray = explode(' ',trim($content_text));
foreach ($resultArray as $key => $item)
{
if (in_array($item,["|",";",".","-","=",":","{","}","[","]","(",")"]))
{
$resultArray[$key] = '';
}
}
$resultArray = array_filter($resultArray);
return count($resultArray);
}