Introduction to PHP for Os X by Example
Basic File Access
- Use the functions file_exists() and is_readable() to check that the file we want to read from exists and can be read.
- The file_get_contents() function reads the entire content of a file into a variable.
- Use str_replace() to replace sections of a string (can be a whole page) with another string.
Note: str_replace acts on a string recursively.
- If the server running the PHP script is behind an authenticated proxy/firewall then the file_get_contents() function will not work for remote files.
- Note: The practice of stripping content from another web site and using it in your own is know as “screen scraping”.
N.B. Unless you know that the content you are scraping is “in the public domain” you should get permission to use it.
Resources