I'm trying to count the vowels in a lengthy text, provided by a .txt file. I can successfully open the file and echo it out into the browser. What I can't seem to do is get my script to do the actual vowel counting and I'm not entirely sure why. I'm supposed to output the vowel count to a file that doesn't previously exist, but is referred to as "file_output1.txt". I'm not sure if this is what is causing the issue, if I'm not properly accessing the file to enable the count to occur, or if I made a syntax error my eyes just can't seem to catch right now.
This is what I've done so far, but I'm not getting the count to fill. There are hundreds of vowels in the text file and it keeps spitting out: "There are (0) vowels". I have counted letters in a string before, but I am having trouble doing it with the file. Any advice?
<?php
#openfile
$file = "Assignment2inputfile.txt" ;
$document = fopen($file,r);
echo fread($document,filesize("Assignment2inputfile.txt"));
?>
<html>
<br><br>
</html>
<?php
#vowelcount
$vowels = array("a", "e", "i", "o", "u");
$length = strlen($_POST["file_output1.txt"]);
$count = 0;
for ($i =0; $i = $length; $i++)
{
if (array_search($_POST["file_output1.txt"][$i], $vowels))
{
$count++;
}
}
echo 'There are (' . $count . ') vowels ' . $_POST["file_output1.txt"] .'.'; ;
fclose($document);
?>
This is how I counted letters before, but this time it is not a short string input. How can I do this, for the vowels, but with a file? Should it work about the same?
<?php
$string = "UniversityofNorthTexasDepartmentofInformationScience";
$tcount = substr_count($string,t);
$Tcount = substr_count($string,T);
print "Total amount:" ;
print $tcount + $Tcount ;
?>