اريد كود ب php او جافاسكربت لحساب عدد الكلمات في صفحة

السلام عليكم


اريد كود ب php او جافاسكربت لحساب عدد الكلمات في صفحة

يوجد بها اكثر من 200 كلمة على شكل اسماء

مثال:

khaled

ahmed

rachid

mohamed

said

.... الخ


شكرا على ردودكم اخواني

@waelaljamal‍ 

@Ahmed_Arafa‍ 

و عذرا على التاخير بسبب المرض... الحمد لله شفيت منه

جربت هذه الشفرة

<?php

$words = file_get_contents("https ://website.com/names.txt");

$totalWords = array_count_values(str_word_count(strip_tags($words),1)) ;

echo 'Total : ' .count($totalWords);

?>

ولكن هناك كلمات مثل adam.dian78

تحسبها كلمتين منفصلتين و انا اريد ان تحسب كلمة واحدة

ممكن مساعدة من فضلكم .

يمكنك استخدام هذه الدالة:

<?php
// PHP program to count number
// of words in a string
// Function to count the words
function get_num_of_words($string) {
    $string = preg_replace('/\s+/', ' ', trim($string));
    $words = explode(" ", $string);
    return count($words);
}
$str = " Geeks for Geeks ";
// Function call
$len = get_num_of_words($str);
// Printing the result
echo $len;
?>

يمكنك استخدام هذه الدالة:

<?php

// PHP program to count number

// of words in a string

// Function to count the words

function get_num_of_words($string) {

    $string = preg_replace('/\s+/', ' ', trim($string));

    $words = explode(" ", $string);

    return count($words);

}

$str = " Geeks for Geeks ";

// Function call

$len = get_num_of_words($str);

// Printing the result

echo $len;

?>