A php code to read the content of a webpage.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ngungo
Forum Commoner
Posts: 75
Joined: Thu Jun 08, 2006 10:45 pm

A php code to read the content of a webpage.

Post by ngungo »

Hi,

I am a .NET programmer switching to php. I used to do this with C#, I wonder if someone can give me a hint of how to read in the content of a webpage provided an URL. Thanks in advance.

ngungo
Last edited by ngungo on Thu Jun 15, 2006 9:09 am, edited 2 times in total.
User avatar
TheMoose
Forum Contributor
Posts: 351
Joined: Tue May 23, 2006 10:42 am

Post by TheMoose »

ngungo
Forum Commoner
Posts: 75
Joined: Thu Jun 08, 2006 10:45 pm

Post by ngungo »

Thanhs, The Moose.

I got that working. Now is a subsequent question: Is there a php function which serves a html file? Basically, it would do this sequence:

fopen();
file_read_contents_();
echo();
User avatar
TheMoose
Forum Contributor
Posts: 351
Joined: Tue May 23, 2006 10:42 am

Post by TheMoose »

Code: Select all

$contents = file_get_contents("http://www.somedomain.com/index.html");
echo $contents;  // or print($contents);
ngungo
Forum Commoner
Posts: 75
Joined: Thu Jun 08, 2006 10:45 pm

Post by ngungo »

This would almost solve my problem, but how do I display a url with a parameter. For example:

Code: Select all

http://www.somedomain.com/index.html?option=3
User avatar
TheMoose
Forum Contributor
Posts: 351
Joined: Tue May 23, 2006 10:42 am

Post by TheMoose »

Just use that as the URL for file_get_contents().
ngungo
Forum Commoner
Posts: 75
Joined: Thu Jun 08, 2006 10:45 pm

Post by ngungo »

TheMoose,

It does exactly as it would, but not to my intention.
Maybe I post the wrong question :( . Lets do it again.

How do I browse a webpage by php as exactly I type its url in the address box of a browser?

And thanks for being patience. ngungo
ngungo
Forum Commoner
Posts: 75
Joined: Thu Jun 08, 2006 10:45 pm

Post by ngungo »

Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I found this works perfectly but feel addly bacause I have to redirect the url:

Code: Select all

$contents = "<html><head><meta HTTP-EQUIV=\"Refresh\" CONTENT=\"0;URL=" . 
  "http://www.somedomain.com/index.html?option=3\">" .
  "</head><body></body></html>";
echo $contents;

Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
ngungo
Forum Commoner
Posts: 75
Joined: Thu Jun 08, 2006 10:45 pm

Post by ngungo »

This is another one, much simpler:

Code: Select all

header('Location: http://www.somedomain.com/index.html?option=3');
Post Reply