greenba Posted September 19, 2006 Share Posted September 19, 2006 Hi,lets say I have an html page at www.domain.com/page.htmlwhat I would like is to get the html code in one string with PHP.any ideas,chears Quote Link to comment https://forums.phpfreaks.com/topic/21273-resolved-read-html-with-php/ Share on other sites More sharing options...
Orio Posted September 19, 2006 Share Posted September 19, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/21273-resolved-read-html-with-php/#findComment-94634 Share on other sites More sharing options...
HuggieBear Posted September 19, 2006 Share Posted September 19, 2006 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]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/21273-resolved-read-html-with-php/#findComment-94636 Share on other sites More sharing options...
greenba Posted September 19, 2006 Author Share Posted September 19, 2006 thank you Quote Link to comment https://forums.phpfreaks.com/topic/21273-resolved-read-html-with-php/#findComment-94648 Share on other sites More sharing options...
Orio Posted September 19, 2006 Share Posted September 19, 2006 [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]RegardsHuggie[/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]<?phpecho(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 3Warning: 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. Quote Link to comment https://forums.phpfreaks.com/topic/21273-resolved-read-html-with-php/#findComment-94767 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.