In our HTML directory, we also have a list of territories.
Let's include those as well within their own group.
If we want to work with the entire file as a single string,
we can use a function called file_get_contents.
And pass the path to the file.
Now we have the entire contents of the file as a string, and
we can do with it as we please.
Let's say we just want to convert the entire string to lowercase before we use
it in our drop-down.
Let's view this in the browser.
You can see that the territories listed are lowercase.
Let's try one more function.
We can also pull in the entire file as an array of individual lines.
Let's add the Armed Forces locations as well.
Our $state_array = file, and we'll pass it the file.
Now we can loop through each of these lines just like we would any other array.
Let's say that we want to remove the Armed Forces text from each item
since we already have a heading that says Armed Forces.
Foreach ($state_array as $line) {
We'll str_replace again.
And we'll replace Armed forces with an empty string.
Let's view this file in the browser once more.
Now we have the Armed Forces added to our drop-down as well without the text
Armed Forces before each of the items.
These are the three basic ways we can interact with a file on our system.
Open a connection to the file, and handle it line-by-line before closing it.
Work with the entire file as a string.
Work with the entire file as an object or an array.
We'll be expanding upon these objects and arrays in the next section.
But before that, let's take a look at writing files.