Paul help!;11051437 wrote:Hi guys.
... I don't get it! Surely the end of lines characters are the last few characters in the string?
EOL characters are the ones that get entered when you hit 'enter' or return' to start a new line. They are what separates this line...
...from this line. They are the New Line (\n) and Carriage Return (\r) characters. They are the 10th and 13th chars on the ASCII chart. In PHP, you can get them into a string in a number of ways:
// specify a scalar string value using the backslash to escape
$newline = "\n";
$carriage_return = "\r";
// using the chr function
$newline = chr(10);
$carriage_return = chr(13);
Paul help!;11051437 wrote:2) In reference to folders, what is the difference between:
./
and
/
Yes they are totally different. Note that these are linux file path conventions. Windows file paths are quite different. The period followed by a slash means the current working directory. Whenever you run a script or open a terminal window on a linux machine, there's this idea that you have a current working directory. You can change that working directory using the cd command.
The slash all by itself refers to the absolute root of your file system. This means the lowest, most basic level of your file system. The folder that contains all other folders. If you start a path with just the slash (no period first) then you are specifying an absolute path from the root of your file system. This is helpful if you need to specify some file in a totally different location. This approach has its advantages and disadvantages that you'll just have to learn over time.
cd /home/sneakyimp # changes working directory to my home folder
ls ./ # lists contents of current working dir, which is /home/sneakyimp
ls / #lists the contents of the file system root
cd /var/www #changes my working directory to the /var/www folder
ls . # lists the current working directory
cd . # this doesn't really do anything
ls .. # two dots refers to the parent of the current working directory. I.e., "up"
cd .. # this goes "up" a directory. E.g., from /var/www to /var
Changing your current working directory is helpful because it means you don't have to type the really long absolute paths to the files you are working with. You can refer to files in the cwd without typing their whole path. You'll note that the real difference is whether the path starts with a slash or a period. A single period (.) refers to the cwd. Two periods (..) refers to the parent of the cwd.
Paul help!;11051437 wrote: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)?
Just like decimal or binary numbers, octal numbers can be arbitrarily long. You can't express 1,000,000,000 with just 3 octal digits. I would encourage you to run the command without the substr bit to see what you get:
echo sprintf( "%o", fileperms("/home/sneakyimp/my_file.txt"); // I get 100644
I'm not sure what the starting 10 are for myself. I suspect it has something to do with [man]fileperms[/man] or [man]sprintf[/man]. Try reading the docs and you may find a clue. I do know what the 0644 means just because I'm familiar with *nix-style file permissions. The 6 means that the owner of the file can read and write it. The next 4 means that the group assigned to the file can read it. The final 4 means that any user on the machine can read the file.
Paul help!;11051437 wrote: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?
Hmm. I almost never work with PHP on windows so I'm no authority but I would say NO that you have to deal with windows and linux file permissions separately because they are pretty different. Certain file-related functions like [man]file_exists[/man] or [man]file_get_contents[/man] and so on should work on both systems but windows paths (e.g., C:\windows\httpd) are very different than linux file paths (/var/www). Writing code that works on both systems is entirely feasible, but takes a bit more work. I'm not exactly sure what you mean when you say "can I type up permissions."
Paul help!;11051437 wrote: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?
PCRE functions like [man]preg_replace[/man] are tremendously powerful and I love them. The price for that power is that you have to learn the very peculiar language and syntax of Regular Expressions. These are a bit of a mind-bender, but if you start learning them, it can be quite rewarding. It's sort of like the Kung Fu which doesn't help at first, but once you master it after years of getting your ass kicked, you become the new sensei.
The meaning of characters in a regular expression depends on the context where they appear. In your regular expression, the square brackets [] indicate "here is a group of characters" and within that context the ^ char says "exclude the following characters within this square bracket section". The dash must be hyphenated when you put it within a square bracket section because the dash has a specific meaning in that particular context. You see the other dashes A-Z and a-z and 0-9 so you might realize that a dash in square brackets indicates that a range is being exressed. The dash in A-Z means "all chars between A and Z." If you want to express an actual dash char and not a range, you have to "escape" the dash with a backslash. This is all based on some elaborate sequence of syntax rules and stuff and just reading about will probably bore you to death. Try experimenting.
In effect, your preg_replace command says replace every character except for those described within your angle brackets with the empty string.