Jump to content

Archived

This topic is now archived and is closed to further replies.

greenba

[RESOLVED] Read html with php

Recommended Posts

Hi,

lets say I have an html page at www.domain.com/page.html
what I would like is to get the html code in one string with PHP.

any ideas,

chears

Share this post


Link to post
Share on other sites
I would use cURL for this task. Make sure you have it installed.

[code]<?php

$url="http://www.domain.com/";

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);

$html=curl_exec($ch);
curl_close ($ch);

echo htmlentities($html);

?>[/code]

Orio.

Share this post


Link to post
Share on other sites
There's a function just for this...

It's called [url=http://www.php.net/manual/en/function.file-get-contents.php]file_get_contents[/url]

[quote]
I would use cURL for this task. Make sure you have it installed.
[/quote]

cURL is overkill for what greenba wants.  That is of course if his/her description is correct  :)

Quote from the manual...

[quote]
file_get_contents() is the preferred way to read the contents of a file into a string. It will use memory mapping techniques if supported by your OS to enhance performance.
[/quote]

Regards
Huggie

Share this post


Link to post
Share on other sites
[quote author=HuggieBear link=topic=108627.msg437220#msg437220 date=1158674542]

[quote]
I would use cURL for this task. Make sure you have it installed.
[/quote]

cURL is overkill for what greenba wants.  That is of course if his/her description is correct  :)

Quote from the manual...

[quote]
file_get_contents() is the preferred way to read the contents of a file into a string. It will use memory mapping techniques if supported by your OS to enhance performance.
[/quote]

Regards
Huggie
[/quote]




I may be wrong- but I think file_get_contents() won't work everytime. I tried to do a simple thing such as:

[code]<?php

echo(file_get_contents("http://www.phpfreaks.com/forums/index.php"));

?>[/code]

I get:
[code]Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /home2/orio/public_html/test.php on line 3

Warning: file_get_contents(http://www.phpfreaks.com/forums/index.php) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /home2/orio/public_html/test.php on line 3[/code]


But I guess that's only because the php.ini is set that way...
Yep found it:
"allow_url_fopen- Off"

So cURL is the best option for me :)

Orio.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.