There is a file 1.txt with the words:
- text12
- text123
text1234
.., etc. (1 word per line)
idea: read this file into an array, display the total number of lines in the file, further analysis of each word: namely: word output - the number of letters in this word, and you need to show the first and last letter of the word. Without a cycle, everything shows up well, I try with the cycle, it shows everything wrong, help me figure out what's wrong, where my mistake$fp = file("1.txt"); echo 'Количество строк в файле: '.count($fp); echo "<hr>"; for ($i = 0; $i <= count($fp); $i++) { $fp = file("1.txt"); $str = trim($fp[i]); $word = $fp[$i]; echo "<hr>".$word."</br>"; echo "Букв: ".iconv_strlen($word)."</br>"; //количество букв в слове echo "Первая: <b>(".$word{0}.")</b>"; //первая буква echo " Последняя: <b>(".substr($word, strlen($word)-1, 1).")</b></br>"; //последняя буква }that's what shows
Number of lines in the file: 3
text12
Letters: 8
First: (t) Last: ()
text123
Letters: 9
First: (t) Last: ()
text1234
Letters: 8
First: (t) Last: (4)
Letters: 0
First: () Last: ()
It also shows 4 line which is not
trimand checking for emptiness. - u_mulder