get url content PHP [duplicate]
original answer moved to this topic .
original answer moved to this topic .
As I said, your example is working fine for me… But try this way using curl instead: //base url $base=”https://play.google.com/store/apps”; $curl = curl_init(); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_URL, $base); curl_setopt($curl, CURLOPT_REFERER, $base); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); $str = curl_exec($curl); curl_close($curl); // Create a DOM object $html_base = new simple_html_dom(); // … Read more
Try this function in place of file_get_contents(): <?php function curl_get_contents($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); return $data; } It can be used just like file_get_contents(), but uses cURL. Install cURL on Ubuntu (or other unix-like operating system with aptitude): sudo apt-get install php5-curl … Read more
I’ve had this problem too, when I working on a little test server at home. The domain name is resolved to your external IP address, and a request is sent. But because the request is coming from inside your network, the router doesn’t recognise it as a normal request. It probably has a web interface … Read more
Check file_get_contents PHP Manual return value. If the value is FALSE then it could not read the file. If the value is NULL then the function itself is disabled. To learn more what might gone wrong with the file_get_contents operation you must enable error reporting and the display of errors to actually read them. # … Read more
Depending on your PHP configuration, this may be a easy as using: $jsonData = json_decode(file_get_contents(‘https://chart.googleapis.com/chart?cht=p3&chs=250×100&chd=t:60,40&chl=Hello|World&chof=json’)); However, if allow_url_fopen isn’t enabled on your system, you could read the data via CURL as follows: <?php $curlSession = curl_init(); curl_setopt($curlSession, CURLOPT_URL, ‘https://chart.googleapis.com/chart?cht=p3&chs=250×100&chd=t:60,40&chl=Hello|World&chof=json’); curl_setopt($curlSession, CURLOPT_BINARYTRANSFER, true); curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, true); $jsonData = json_decode(curl_exec($curlSession)); curl_close($curlSession); ?> Incidentally, if you just want … Read more
try this: function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); $data = curl_exec($ch); curl_close($ch); return $data; }
First of all, the first rule of multipart Content-Type is to define a boundary that will be used as a delimiter between each part (because as the name says, it can have multiple parts). The boundary can be any string that is not contained in the content body. I will usually use a timestamp: define(‘MULTIPART_BOUNDARY’, … Read more
One approach that you can use on smaller files that can fit into your memory twice: $data = file(‘myfile’); // reads an array of lines function replace_a_line($data) { if (stristr($data, ‘certain word’)) { return “replacement line!\n”; } return $data; } $data = array_map(‘replace_a_line’, $data); file_put_contents(‘myfile’, $data); A quick note, PHP > 5.3.0 supports lambda functions … Read more
It means your server cannot connect to the outside world This probably won’t change anything given the DNS issues So, If you have permission, try changing the name servers in your /etc/resolv.conf file to other nameservers.