File_Get_Contents
One of the most powerful functions in PHP is the simple file_get_contents(). With it, you can load an entire file, text, image or whatever type you want, into a variable for later display or manipulation. Better yet, that file can be anywhere on the Internet, just use an URL instead of file path, and it will return a web page.
$work = @file_get_contents('http://www.ranchocorrecaminos.com/index.htm');
The @ symbol before the command tells PHP not to send error messages. You use that when the PHP code is being executed on a web page intended for public viewing. If you are retrieving the file for your own use, you leave the @ out so that you will be informed if an error occurs.
This simple command is the basis for most PHP scrapers, bots and dynamic aggregation sites. Simple, yet very powerful!
Filed under: Functions | Leave a Comment
Search
-
You are currently browsing the PHP Basics weblog archives.
No Responses Yet to “File_Get_Contents”