PHP to Ruby
Convert PHP code into Ruby!
-
file_get_contents
Posted on November 18th, 2010 1 commentThe file_get_contents() function in PHP reads the content of a file into a string (or reads the HTML of a web page into a string).
PHP
$body = file_get_contents( 'http://www.google.com' ); echo $body; /* ... HTML source of www.google.com ... */
To replicate this functionality in Ruby, we will use the Net/HTTP class from Ruby.
Ruby
require 'net/http'; uri = 'http://www.google.com'; body = Net::HTTP.get_response(URI.parse(self)).body; p result # ... HTML source of www.google.com ...
This page was contributed by Cemil Necefov. Thanks!
One response to “file_get_contents”
-
require ‘open-uri’
puts open(’http://www.google.com’).read
Leave a reply
-


