There are a selection of functions from the bottom up, separated by horizontal rules.
I created a file named lyric.txt, copied some lyrics. I also use a variable named $lyric in some places.
How many times does a particular word show up in my text file lyric.txt?
(The function in fileio.php references the variable $lyric in that same file and the substring to search for, $testedWord, in this file. A form saves the entered data to a file and then retrieves it here.)
Tested these functions. They worked. Displaying the lyrics here for convenience so the function above can be tested.
// readFileIntoString(); // no line breaks
// readFileLineByLine(); // as in original file with line breaks
Summarizing a few filesystem functions on lyric.txt:
Number of characters: | 1092 |
File Last Accessed: | March 20 2024 16:39:17. |
Content Last Modified: | March 29 2022 03:32:42. |
File Last Modified: | March 20 2024 19:53:25. |
I find it odd that they would put a period after the timestamp.
I understood your CSV example and duplicated it with my file jlCsv.txt.
"Create an array and save it to to a file as a comma separated list (fputcsv) when writing, and turn the comma separated list back into an array (fgetcsv) when reading."
I then manually created the bands.csv file and wrote the following function to try to work towards "reading an actual multi-record CSV file and turning it into multiple arrays with column headers being the keys." Interestingly the first function produces an array and the second simply echos the original data, but I thought it was cool so I left it for now.
©2022 Darlene McCormick • Web page by me