I have a PHP script that reads the contents of a file and stores it into a variable. I want to split the text stored by the new line entries and then search the array[0] value for a specific value.
That is my idea. Here is my situation.
I have a directory file with specific entries.
Entry1_two_term3_stuff
Entry2_two_term3_stuff
Entry3_two_term3_stuff
This will be stored into a variable. How do I search this for Entry2 and then get the whole line to work with?
If you can, use the file() function to load the file into array, already split by newlines:
If not, you can use
You might want to use \r\n if you’re on Windows and file contains CR characters.
To search the array, use foreach:
In the end, write contents back to some file: