file-get-contents

simple html dom scraping large html file

南笙酒味 提交于 2019-11-30 20:40:05
I need to scrape a large html file (eg: http://www.indianrail.gov.in/mail_express_trn_list.html ) using simple html dom. I started with a simple script: <?php require "simple_html_dom.php"; echo file_get_html('http://www.indianrail.gov.in/mail_express_trn_list.html')->plaintext; ?> which shows nothing, just a blank page with the error message in Apache error.log file PHP Notice: Trying to get property of non-object in /var/www/index.php on line 3 PHP Notice: Trying to get property of non-object in /var/www/index.php on line 3 at the same time all other pages (eg: http://www.indianrail.gov.in

file_get_contents not working for local files

早过忘川 提交于 2019-11-30 15:58:05
问题 I recently upgraded my XAMPP from PHP 5.2 to 5.3.1 I seem to be having a problem with file_get_contents(). I can use the function to get something like "http://www.google.com", but it times out when I use it on a domain I have setup locally e.g. "http://localhost/my_dir/my_css_file.css". I'm not really sure what the problem is. If it's a bug, is there a viable alternative? Kindly advise. 回答1: Try to use include() instead of file_get_contents() . <?php include($_SERVER['HTTP_HOST'] . "/my_dir

file_get_contents script works with some websites but not others

半城伤御伤魂 提交于 2019-11-30 10:26:22
I'm looking to build a PHP script that parses HTML for particular tags. I've been using this code block, adapted from this tutorial : <?php $data = file_get_contents('http://www.google.com'); $regex = '/<title>(.+?)</'; preg_match($regex,$data,$match); var_dump($match); echo $match[1]; ?> The script works with some websites (like google, above), but when I try it with other websites (like, say, freshdirect), I get this error: "Warning: file_get_contents( http://www.freshdirect.com ) [function.file-get-contents]: failed to open stream: HTTP request failed!" I've seen a bunch of great

how to use cURL in facebook graph api request

倾然丶 夕夏残阳落幕 提交于 2019-11-30 10:05:57
I am getting the information to facebook graph api using file_get_contents() but sometimes I am receiving an error. I found out that cURL must be used instead of file_get_contents(). The problem is, I don't know how to use cURL with the URL that I need to pass. if I converted file_get_contents($graph_url); into cURL, what will be the code? here is the content of $graph_url $graph_url= "https://graph.facebook.com/me/photos?" . "url=" . urlencode($photo_url) . "&message=" . urlencode('') . "&method=POST" . "&access_token=" .$access_token; $graph_url= "https://graph.facebook.com/me/photos";

php json returning bool(false)

风流意气都作罢 提交于 2019-11-30 09:41:29
问题 Any thoughts as to why the following is not working. $request_url = "someurl?myId=$id"; //returns feed like above $json = file_get_contents($request_url, true); //getting the file content $decode = json_decode($json, true); var_dump($json); When I paste the request_url into a browser I get back the json data but if I try in php the var_dump is simply bool(false); Any ideas?? Update and fix OK guys thanks for all the help. Ye helped me track this one down. It turned out to be the php.ini is

JSON to PHP Array using file_get_contents

戏子无情 提交于 2019-11-30 07:54:57
问题 I am trying to fetch the below json content using a magazine api. The output of the json is like this. i want the below json to convert to php array. { "bpath": "http://www.sampledomain.com/", "clist": [ { "cid": "11", "display_type": "grid", "ctitle": "abc", "acount": "71", "alist": [ { "aid": "6865", "adate": "2 Hours ago", "atitle": "test", "adesc": "test desc", "aimg": "", "aurl": "?nid=6865", "weburl": "news.php?nid=6865", "cmtcount": "0" }, { "aid": "6857", "adate": "20 Hours ago",

Remotely download a file from an external link to my server - download stops prematurely

假如想象 提交于 2019-11-30 05:59:55
问题 I have a page set where I enter the url of an file and I have my server download that file and save it into a folder on my server. The issue is that I dont know how to download a file to my server. I have tried both of the following methods, and they both didn't work. This one throws an error about a failed open stream: $url = 'http://www.example.com/file.zip'; $enc = urlencode($url); $dir = "/downloads/file.zip"; $raw = file_get_contents($enc); file_put_contents($dir, $raw); This one works

simple html dom scraping large html file

有些话、适合烂在心里 提交于 2019-11-30 05:16:32
问题 I need to scrape a large html file (eg: http://www.indianrail.gov.in/mail_express_trn_list.html) using simple html dom. I started with a simple script: <?php require "simple_html_dom.php"; echo file_get_html('http://www.indianrail.gov.in/mail_express_trn_list.html')->plaintext; ?> which shows nothing, just a blank page with the error message in Apache error.log file PHP Notice: Trying to get property of non-object in /var/www/index.php on line 3 PHP Notice: Trying to get property of non

php json returning bool(false)

二次信任 提交于 2019-11-29 16:55:42
Any thoughts as to why the following is not working. $request_url = "someurl?myId=$id"; //returns feed like above $json = file_get_contents($request_url, true); //getting the file content $decode = json_decode($json, true); var_dump($json); When I paste the request_url into a browser I get back the json data but if I try in php the var_dump is simply bool(false); Any ideas?? Update and fix OK guys thanks for all the help. Ye helped me track this one down. It turned out to be the php.ini is configured to disallow the opening of urls so the file_get_contents would not work. I found the following

how to use cURL in facebook graph api request

笑着哭i 提交于 2019-11-29 15:10:43
问题 I am getting the information to facebook graph api using file_get_contents() but sometimes I am receiving an error. I found out that cURL must be used instead of file_get_contents(). The problem is, I don't know how to use cURL with the URL that I need to pass. if I converted file_get_contents($graph_url); into cURL, what will be the code? here is the content of $graph_url $graph_url= "https://graph.facebook.com/me/photos?" . "url=" . urlencode($photo_url) . "&message=" . urlencode('') . "