hi friends,
is there a possibility of counting characters in a file like .pdf or .doc ?
cheers,
juline
count characters in file
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
not too sure but maybe
I know that applies to text, but not sure about documents and such.
Code: Select all
$contents = file_get_contents($file);
echo strlen($contents);thanx.
i dcripted following code which is uploading a file and counting the chracters.
but the output is not exactly correct. it puts more out than actually is in file. then i would like to devide tha amount of chars into 50. and after displaying the result delete the uploaded file.
can someone help me please ?
i tried the following:
regards,
juline
i dcripted following code which is uploading a file and counting the chracters.
Code: Select all
<?php
$uploaddir = 'uploads/temp/';
$filename=$_FILESї'file']ї'name'];
if (move_uploaded_file($_FILESї'file']ї'tmp_name'], $uploaddir."$filename"))
{
$datei=fopen("uploads/temp/$filename", r);
$content=file_get_contents("uploads/temp/$filename");
echo "Filename: ";
echo "$filename";
echo "<br>";
echo "Chars ";
echo strlen($content);
}
?>can someone help me please ?
i tried the following:
Code: Select all
<?php
$uploaddir = 'uploads/temp/';
$filename=$_FILESї'file']ї'name'];
if (move_uploaded_file($_FILESї'file']ї'tmp_name'], $uploaddir."$filename"))
{
$datei=fopen("uploads/temp/$filename", r);
$content=file_get_contents("uploads/temp/$filename");
$norm=$content/50;
echo "Dateiname: ";
echo "$filename";
echo "<br>";
echo "Zeichen ca. ";
echo strlen($content);
echo " <br>";
echo "Normzeile(n): ";
echo "$norm";
}
?>regards,
juline
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
both pdf and doc are binary file formats. You won't be able to just open the file with any arbitrary function and read out all the actual text data.
The code you are working with right now is based off the file's size. Not the character counts contained in their encoding. This is the reason the sizes you recieve back are inaccurate.
The code you are working with right now is based off the file's size. Not the character counts contained in their encoding. This is the reason the sizes you recieve back are inaccurate.