Page 1 of 1
A php code to read the content of a webpage.
Posted: Thu Jun 08, 2006 11:10 pm
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
Posted: Thu Jun 08, 2006 11:41 pm
by TheMoose
Posted: Thu Jun 15, 2006 9:13 am
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();
Posted: Thu Jun 15, 2006 9:24 am
by TheMoose
Code: Select all
$contents = file_get_contents("http://www.somedomain.com/index.html");
echo $contents; // or print($contents);
Posted: Thu Jun 15, 2006 9:28 am
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
Posted: Thu Jun 15, 2006 9:36 am
by TheMoose
Just use that as the URL for file_get_contents().
Posted: Thu Jun 15, 2006 9:45 am
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
Posted: Thu Jun 15, 2006 9:56 am
by ngungo
Weirdan | Please use 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
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]
Posted: Thu Jun 15, 2006 12:49 pm
by ngungo
This is another one, much simpler:
Code: Select all
header('Location: http://www.somedomain.com/index.html?option=3');