Hi guys.
I have some random questions relative to the topic of 'files' and 'directories'.
I have just finished reading a chapter on the topic of 'files' and 'directories', from a php book I am in the process of reading.
There were a few things during the reading of the chapter that were slightly unclear to me and I have a number of questions (below) that I need some help understanding:
1) In php, what does 'end-of-line characters' mean? Here is an extract from the book I am reading (and I don't understand their meaning behind 'end-of-line characters'):
As with other flags in PHP you can combine any of these flags with the bitwise OR operator (see Chapter 3
for details). For example, the following code looks for a file in the include path and, when found, reads
the file, ignoring any empty lines in the file:
$lines = file( “myfile.txt”, FILE_USE_INCLUDE_PATH | FILE_SKIP_EMPTY_LINES );
As with fopen() , you can also use file() to fetch files on a remote host:
$lines = file( “http://www.example.com/index.html” );
foreach ( $lines as $line ) echo $line . “ < br / > ”;
A related function is file_get_contents() . This does a similar job to file() , but it returns the
file contents as a single string, rather than an array of lines. The end - of - line characters are included in
the string:
$fileContents = file_get_contents( “myfile.txt” );
... I don't get it! Surely the end of lines characters are the last few characters in the string?
2) In reference to folders, what is the difference between:
./
and
/
............ because they both seem to do the same thing from what I can see. Is there a difference?
3) Below is an extract from my book, I find very confusing:
You can also use the fileperms() function to return an integer representing the permissions that are set
on a file or directory. For example, to print the octal value of the permissions on a file you might use:
chmod( “myfile.txt”, 0644 );
echo substr( sprintf( “%o”, fileperms( “myfile.txt”) ), -4 ); // Displays
“0644”
(The call to substr() is used to return just the last four digits, because the other octal digits in the
returned value aren ’ t relevant.)
The thing I do not understand is why (above) they say that substr() is used to return the last four digits, because the other octal digits in the returned value aren’t relevant.
Octal numbers are only 3 digits long aren't they? So how does substr (above) manage to extract 4 digits (which should be impossible, since the conversion specification converted the argument to an octal number)?
4) Below is another extract from the book:
File and directory modes only work on UNIX systems such as Linux and Mac OS; they have no effect
when used on Windows machines.
... What I want to know is: can I type up permissions on my windows operating system and upload them to a linux server, and will they still work?
5) Below is a snippet of code from the book I am reading:
$filename = preg_replace( “/[A-Za-z0-9_- ]/”, “”, $filename );
In the book it says that the regular expression (above) strips all the characters from the filename except letters,
digits, underscores, hyphens, and spaces.
What I need to know is: what part of:
/[A-Za-z0-9_- ]/
..... communicates "except for"?
and why does the dash need to be escaped?
Paul.