Concept
How can PHP use URLs as file names?
ComputerScienceOne / Closing Files
"44.2.1. Using URLs A nice feature of PHP is that you can use URLs as file names to read and write to a URL. “Reading” from a URL mean connecting to a remote resource, such as a webservice and downloading its contents (which may be HTML, XML or JSON data). Writing to a URL may be used to post data to a web page in order to receive a response. As an example, we can download a webpage in PHP as follows.\n\n1 $h = fopen(\"http://cse.unl.edu\", \"r\");\n\n2 $contents = \"\";\n\n3 while(!feof($h)) {\n\n4 $contents .= fgets($h);\n\n5 }\n\n6\n\n7 //or just:\n\n8 $contents = file_get_contents(\"http://cse.unl.edu\");"
Related Ideas
- How do you open and validate files in PHP?ComputerScienceOne · Opening Files
- How does PHP handle file input and output?ComputerScienceOne · Opening Files
- How can you write values to a plaintext file in PHP?ComputerScienceOne · Using URLs
- How are files read, written, and properly managed?ComputerScienceOne · Paths
- How do file names, extensions, and working directories affect file paths?ComputerScienceOne · Paths
- What types of errors can occur when processing files?ComputerScienceOne · Error Handling
- What is the difference between absolute and relative file paths?ComputerScienceOne · Paths
- How should you close files in C?ComputerScienceOne · Closing Files