473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 5764
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: | last post by:
Is it possible for a user to enable permanent cookies but disable session cookies.....this seems like a contradition yet this is what I appear to be reading in online articles?
20
by: CHIN | last post by:
Hi all.. here s my problem ( maybe some of you saw me on other groups, but i cant find the solution !! ) I have to upload a file to an external site, so, i made a .vbs file , that logins to...
13
by: Alison Givens | last post by:
....... that nobody knows the answer. I can't imagine that I am the only one that uses parameters in CR. So, my question again: I have the following problem. (VB.NET 2003 with CR) I have a...
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.