Jump to content

[RESOLVED] Read html with php


greenba

Recommended Posts

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.
Link to comment
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
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.