473,545 Members | 2,543 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.c om");
WebResponse res=req.GetResp onse();
StreamReader sr = new StreamReader(re s.GetResponseSt ream());
String Output=sr.ReadT oEnd();
Response.Write( "The content is : " + Output);
--------

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

Oct 25 '05 #1
11 5775
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.c om");
WebResponse res=req.GetResp onse();
StreamReader sr = new StreamReader(re s.GetResponseSt ream());
String Output=sr.ReadT oEnd();
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.c om");
WebResponse res=req.GetResp onse();
StreamReader sr = new StreamReader(re s.GetResponseSt ream());
String Output=sr.ReadT oEnd();
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*******@gma il.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.c om");
WebRespons e res=req.GetResp onse();
StreamRead er sr = new StreamReader(re s.GetResponseSt ream());
String Output=sr.ReadT oEnd();
Response.Wri te("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*******@gma il.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.c om");
WebRespons e res=req.GetResp onse();
StreamRead er sr = new StreamReader(re s.GetResponseSt ream());
String Output=sr.ReadT oEnd();
Response.Wri te("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*******@gma il.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.c om");
WebRespons e res=req.GetResp onse();
StreamRead er sr = new StreamReader(re s.GetResponseSt ream());
String Output=sr.ReadT oEnd();
Response.Wri te("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_conten ts(), 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_conten ts() 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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2524
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
2448
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 the site, and then i have to select the file to upload.. i used sendkeys.. and i worked perfect.. BUT ... the computer must be locked for security (...
13
2518
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 report with a multiple-value discrete value and a rangevalue. The report shows fine in the viewer, but when I hit the export to pdf
9
3818
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 site for a small club I belong to and one of the features I would like to include is the ability to allow users to upload image files. ...
0
7464
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7396
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7805
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
4943
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3449
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3440
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1874
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.