1. This function is similar to file(), except that file_get_contents() returns the
file in a string, starting at the specified offset up to maxlen bytes. On
failure, file_get_contents() will return FALSE.
file_get_contents() is the preferred way to read the contents of a file into a
string. It will use memory mapping techniques if supported by your OS to enhance
performance.This function is similar to file(), except that file_get_contents()
returns the file in a string, starting at the specified offset up to maxlen
bytes. On failure, file_get_contents() will return FALSE.
file_get_contents() is the preferred way to read the contents of a file into a
string. It will use memory mapping techniques if supported by your OS to enhance
performance.This function is similar to file(), except that file_get_contents()
returns the file in a string, starting at the specified offset up to maxlen
bytes. On failure, file_get_contents() will return FALSE.
file_get_contents() is the preferred way to read the contents of a file into a
string. It will use memory mapping techniques if supported by your OS to enhance
performance.This function is similar to file(), except that file_get_contents()
returns the file in a string, starting at the specified offset up to maxlen
bytes. On failure, file_get_contents() will return FALSE.
file_get_contents() is the preferred way to read the contents of a file into a
string. It will use memory mapping techniques if supported by your OS to enhance
performance.This function is similar to file(), except that file_get_contents()
returns the file in a string, starting at the specified offset up to maxlen
bytes. On failure, file_get_contents() will return FALSE.
file_get_contents() is the preferred way to read the contents of a file into a
string. It will use memory mapping techniques if supported by your OS to enhance
performance.This function is similar to file(), except that file_get_contents()
returns the file in a string, starting at the specified offset up to maxlen
bytes. On failure, file_get_contents() will return FALSE.
file_get_contents() is the preferred way to read the contents of a file into a
string. It will use memory mapping techniques if supported by your OS to enhance
performance.This function is similar to file(), except that file_get_contents()
returns the file in a string, starting at the specified offset up to maxlen
bytes. On failure, file_get_contents() will return FALSE.
file_get_contents() is the preferred way to read the contents of a file into a
string. It will use memory mapping techniques if supported by your OS to enhance
performance.This function is similar to file(), except that file_get_contents()
returns the file in a string, starting at the specified offset up to maxlen
bytes. On failure, file_get_contents() will return FALSE.
file_get_contents() is the preferred way to read the contents of a file into a
string. It will use memory mapping techniques if supported by your OS to enhance
performance.This function is similar to file(), except that file_get_contents()
returns the file in a string, starting at the specified offset up to maxlen
bytes. On failure, file_get_contents() will return FALSE.
file_get_contents() is the preferred way to read the contents of a file into a
string. It will use memory mapping techniques if supported by your OS to enhance
performance.This function is similar to file(), except that file_get_contents()
returns the file in a string, starting at the specified offset up to maxlen
bytes. On failure, file_get_contents() will return FALSE.
file_get_contents() is the preferred way to read the contents of a file into a
string. It will use memory mapping techniques if supported by your OS to enhance
performance.This function is similar to file(), except that file_get_contents()
returns the file in a string, starting at the specified offset up to maxlen
bytes. On failure, file_get_contents() will return FALSE.
2. file_get_contents() is the preferred way to read the contents of a file into a
string. It will use memory mapping techniques if supported by your OS to enhance
performance.This function is similar to file(), except that file_get_contents()
returns the file in a string, starting at the specified offset up to maxlen
bytes. On failure, file_get_contents() will return FALSE.
file_get_contents() is the preferred way to read the contents of a file into a
string. It will use memory mapping techniques if supported by your OS to enhance
performance.This function is similar to file(), except that file_get_contents()
returns the file in a string, starting at the specified offset up to maxlen
bytes. On failure, file_get_contents() will return FALSE.
file_get_contents() is the preferred way to read the contents of a file into a
string. It will use memory mapping techniques if supported by your OS to enhance
performance.This function is similar to file(), except that file_get_contents()
returns the file in a string, starting at the specified offset up to maxlen
bytes. On failure, file_get_contents() will return FALSE.
file_get_contents() is the preferred way to read the contents of a file into a
string. It will use memory mapping techniques if supported by your OS to enhance
performance.
fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
3. list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
4. connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
5. string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
6. (dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
7. fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
8. and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
9. Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
10. The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
11. first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
12. powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
13. Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
14. The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
15. Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
16. this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
17. actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
18. The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
19. fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
20. feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
21. reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
22. can add an argument to fgets to limit the maximum line length. For example, use
this fopen
The fopen function creates the connection to the file. I say "creates the
connection" because in addition to opening a file, fopen can open a URL:
$fh = fopen("http://127.0.0.1/", "r");
This line of code creates a connection to the page above and allows you to start
reading it much like a local file.
Note: The "r" used in fopen indicates that the file is open for reading only.
Because writing to files is beyond the scope of this article, I'm not going to
list all the other options. However, you should change "r" to "rb" if you're
reading from binary files for cross-platform compatibility. You'll see an
example of this later.
feof
The feof command detects whether you have already read to the end of the file
and returns True or False. The loop in Listing 1 continues until you have
reached the end of the file "myfile." Note that feof also returns False if
you're reading a URL and the socket has timed out because you no longer have
data to read.
fclose
Skipping ahead to the end of Listing 1, fclose serves the opposite function of
fopen: It closes the connection to the file or URL. You are no longer able to
read from the file or socket after this function.
fgets
Learn more. Develop more. Connect more.
The new developerWorks Premium membership program provides an all-access pass to
powerful development tools and resources, including 500 top technical titles
(dozens specifically for open source developers) through Safari Books Online,
deep discounts on premier developer events, video replays of recent O'Reilly
conferences, and more. Sign up today.
Jumping back a few lines in Listing 1, you get to the heart of file processing:
actually reading the file. The fgets function is your weapon of choice for this
first example. It grabs a single line of data from your file and returns it as a
string. From there, you can print or otherwise process your data. The example in
Listing 1 nicely prints out an entire file.
If you decide to limit the size of the data chunks that you'll deal with, you
can add an argument to fgets to limit the maximum line length. For example, use
this