470,836 Members | 1,877 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,836 developers. It's quick & easy.

Is it possible to read another web page in PHP?

Is it possible to read another web page in PHP?
If is ASP.NET, the code would be
------------
WebRequest req=WebRequest.Create("http://www.microsoft.com");
WebResponse res=req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream());
String Output=sr.ReadToEnd();
Response.Write("The content is : " + Output);
--------

Would you please tell me the PHP equivalant of this code? Thank you.

Oct 25 '05 #1
11 5561
I think if you go to http://www.php.net/documentation

You will find that in the documentation there is an entire section
dedicated to Filesystem. With many different functions that you may find
useful: eg. fread, fopep anbd many more.

ty*******@gmail.com wrote:
Is it possible to read another web page in PHP?
If is ASP.NET, the code would be
------------
WebRequest req=WebRequest.Create("http://www.microsoft.com");
WebResponse res=req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream());
String Output=sr.ReadToEnd();
Response.Write("The content is : " + Output);
--------

Would you please tell me the PHP equivalant of this code? Thank you.

Oct 25 '05 #2
The web page I'm trying to read is not on the same server. Does fopen
also work for this? Can I read www.microsoft.com with fopen?

Ramon wrote:
I think if you go to http://www.php.net/documentation

You will find that in the documentation there is an entire section
dedicated to Filesystem. With many different functions that you may find
useful: eg. fread, fopep anbd many more.

ty*******@gmail.com wrote:
Is it possible to read another web page in PHP?
If is ASP.NET, the code would be
------------
WebRequest req=WebRequest.Create("http://www.microsoft.com");
WebResponse res=req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream());
String Output=sr.ReadToEnd();
Response.Write("The content is : " + Output);
--------

Would you please tell me the PHP equivalant of this code? Thank you.


Oct 25 '05 #3
My apologies, I missunderstood.

But fopen should still work: *fopen -- Opens file or URL*

Have a read of the fopen documentation entry.


ty*******@gmail.com wrote:
The web page I'm trying to read is not on the same server. Does fopen
also work for this? Can I read www.microsoft.com with fopen?

Ramon wrote:
I think if you go to http://www.php.net/documentation

You will find that in the documentation there is an entire section
dedicated to Filesystem. With many different functions that you may find
useful: eg. fread, fopep anbd many more.

ty*******@gmail.com wrote:
Is it possible to read another web page in PHP?
If is ASP.NET, the code would be
------------
WebRequest req=WebRequest.Create("http://www.microsoft.com");
WebResponse res=req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream());
String Output=sr.ReadToEnd();
Response.Write("The content is : " + Output);
--------

Would you please tell me the PHP equivalant of this code? Thank you.


Oct 25 '05 #4
Thank you, Ramon.
I've visited the manual page, and found, there is a more appropriate
method.

[Scrap]
admin at sellchain dot com
17-Oct-2005 10:34
TIP: If you are using fopen and fread to read HTTP or FTP or Remote
Files, and experiencing some performance issues such as stalling,
slowing down and otherwise, then it's time you learned a thing called
cURL.

Performance Comparison:

10 per minute for fopen/fread for 100 HTTP files
2000 per minute for cURL for 2000 HTTP files

cURL should be used for opening HTTP and FTP files, it is EXTREMELY
reliable, even when it comes to performance.

I noticed when using too many scripts at the same time to download the
data from the site I was harvesting from, fopen and fread would go into
deadlock. When using cURL i can open 50 windows, running 10 URL's from
each window, and getting the best performance possible.

Just a Tip :)
Ramon wrote:
My apologies, I missunderstood.

But fopen should still work: *fopen -- Opens file or URL*

Have a read of the fopen documentation entry.


ty*******@gmail.com wrote:
The web page I'm trying to read is not on the same server. Does fopen
also work for this? Can I read www.microsoft.com with fopen?

Ramon wrote:
I think if you go to http://www.php.net/documentation

You will find that in the documentation there is an entire section
dedicated to Filesystem. With many different functions that you may find
useful: eg. fread, fopep anbd many more.

ty*******@gmail.com wrote:

Is it possible to read another web page in PHP?
If is ASP.NET, the code would be
------------
WebRequest req=WebRequest.Create("http://www.microsoft.com");
WebResponse res=req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream());
String Output=sr.ReadToEnd();
Response.Write("The content is : " + Output);
--------

Would you please tell me the PHP equivalant of this code? Thank you.



Oct 25 '05 #5
fopen worked fine but not on my hosting service.
Warning: fopen(): URL file-access is disabled in the server
configuration...
Nor curl worked. I think it's not installed the server.

Is there any other way to access URL file in PHP?

Ramon wrote:
My apologies, I missunderstood.

But fopen should still work: *fopen -- Opens file or URL*

Have a read of the fopen documentation entry.


ty*******@gmail.com wrote:
The web page I'm trying to read is not on the same server. Does fopen
also work for this? Can I read www.microsoft.com with fopen?

Ramon wrote:
I think if you go to http://www.php.net/documentation

You will find that in the documentation there is an entire section
dedicated to Filesystem. With many different functions that you may find
useful: eg. fread, fopep anbd many more.

ty*******@gmail.com wrote:

Is it possible to read another web page in PHP?
If is ASP.NET, the code would be
------------
WebRequest req=WebRequest.Create("http://www.microsoft.com");
WebResponse res=req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream());
String Output=sr.ReadToEnd();
Response.Write("The content is : " + Output);
--------

Would you please tell me the PHP equivalant of this code? Thank you.



Oct 25 '05 #6
What do you want to do with it? There may be other ways to achieve what
you want

Ian

Oct 25 '05 #7
You could try using fopen() or alternatively some sort of socket
mechanism, only if you are game that is.

There is also file_get_contents(), but I think that works the same way
fopen() does, only it returns a string.
Oct 25 '05 #8
oops, I meant to say file(); not fopen()

Sorry :S
Oct 25 '05 #9
I've found that file() and file_get_contents() generates the same
error. However, I found a working way by searching the internet. I can
achieve what I wanted, but I have to deal with dirty HTTP protocal.
Here is the code. I hope this would help the others too.

$fp = fsockopen("www.google.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: www.google.com\r\n";
$out .= "Connection: Close\r\n\r\n";

fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}

Ramon wrote:
oops, I meant to say file(); not fopen()

Sorry :S


Oct 25 '05 #10
NC
ty*******@gmail.com wrote:

Is it possible to read another web page in PHP?
Yes.
If is ASP.NET, the code would be
------------
WebRequest req=WebRequest.Create("http://www.microsoft.com");
WebResponse res=req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream());
String Output=sr.ReadToEnd();
Response.Write("The content is : " + Output);
--------

Would you please tell me the PHP equivalant of this code?


Prepare to be dazzled:

$output = readfile('http://www.microsoft.com');
echo 'The content is : ', $output;

That's it, really... No need to define three objects in order
to end up with a string. Nifty, huh?

Cheers,
NC

Oct 25 '05 #11
Thank you. That could could have been very useful but
on my hosting server, that generates
Warning: readfile(): URL file-access is disabled in the server
configuration

I think it's still useful for other cases. Thank you.

NC wrote:
ty*******@gmail.com wrote:

Is it possible to read another web page in PHP?


Yes.
If is ASP.NET, the code would be
------------
WebRequest req=WebRequest.Create("http://www.microsoft.com");
WebResponse res=req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream());
String Output=sr.ReadToEnd();
Response.Write("The content is : " + Output);
--------

Would you please tell me the PHP equivalant of this code?


Prepare to be dazzled:

$output = readfile('http://www.microsoft.com');
echo 'The content is : ', $output;

That's it, really... No need to define three objects in order
to end up with a string. Nifty, huh?

Cheers,
NC


Oct 25 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Alison Givens | last post: by
9 posts views Thread by Wayne Smith | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.