A php code to read the content of a webpage.
Moderator: General Moderators
A php code to read the content of a webpage.
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
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.
Code: Select all
$contents = file_get_contents("http://www.somedomain.com/index.html");
echo $contents; // or print($contents);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=3Weirdan | Please use
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]This is another one, much simpler:
Code: Select all
header('Location: http://www.somedomain.com/index.html?option=3');