Reputation: 61
I am using doc2txt.class.php class to get the txt from word file using php and I am using the below code
require("doc2txt.class.php");
$docObj = new Doc2Txt("test.docx");
$txt = $docObj->convertToText();
My word file contains the below text
MWONGOZO WA MAOMBI MAALUMU (MAOMBI YA HATARI).
Huu ni Mfano Tu, Jinsi Ya Kuomba Na Maeneo Ya Kuombea! Unatakiwa pamoja na KUWA NA BIDII, KUMTEGEMEA SANA ROHO MTAKATIFU NI MUHIMU SANA!
MAOMBI MAALUMU YA JINSI YA KUPAMBANA KATIKA VITA VYA KIROHO
Jinsi Ya Kuomba Maombi Haya
But output I get is little different my output is
MWONGOZO WA MAOMBI MAALUMU (MAOMBI YA HATARI).Huu ni Mfano Tu, Jinsi Ya Kuomba Na Maeneo Ya Kuombea! Unatakiwa pamoja na KUWA NA BIDII, KUMTEGEMEA SANA ROHO MTAKATIFU NI MUHIMU SANA! MAOMBI MAALUMU YA JINSI YA KUPAMBANA KATIKA VITA VYA KIROHOJinsi Ya Kuomba Maombi Haya
as you can see output contains this word KIROHO Jinsi as one word KIROHOJinsi so when I count the number of words it gives 45 words but actually there are 46 words.
Is there any way to resolve this issue?
Upvotes: 2
Views: 456
Reputation: 375
I have checked this code for txt file and it is working fine. I think this might help you. Thanks
$myfile = file_get_contents("test.txt");
$array = explode("\n", $myfile);
$count = null;
if (!empty($array))
{
$i = 0;
foreach ($array as $rowarray)
{
$a1 = array_filter(explode(" ", trim($rowarray)));
$count = $count + count($a1);
}
echo $count;
}
Upvotes: 1