Bifalgorithm post · Computer science one · Using URLs

How can PHP use URLs as file names?

How can PHP use URLs as file names? (Computer science one · Using URLs) — "A nice feature of PHP is that you can use URLs as file names to read and write to a…

Ideas in this flowchart

  • PHP supports reading from and writing to URLs as file names.
  • Reading from a URL connects to a remote resource and downloads its contents.
  • The remote resource may be a web service.
  • Downloaded contents may be HTML, XML, or JSON data.
  • Writing to a URL can post data to a web page and receive a response.
  • PHP can download a web page from a URL.
  • The fopen method opens the URL for reading.
  • A loop reads lines and appends them until the end of the file is reached.
  • The file_get_contents function provides a shorter alternative for downloading the page.
Feed/

How can PHP use URLs as file names?

No cover

Channel

Computer science one

1 page

"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\");"

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.