Questions tagged [file-get-contents]

In PHP, 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.

In PHP, file_get_contents is used to read an entire file into a single string. Depending on the server configuration, it can also be used to read URLs as well. It differs from file(), in that file is designed to return a resource pointer and then used read the file in chunks (i.e. CSV files). Use file for large files that should not be read all at once. Use file_get_contents to read smaller files and files that cannot be read as easily read in chunks (i.e. JSON)

For more details see the PHP manual entry.

2607 questions
0
votes
1 answer

Caching SQL Lookups & Retrieving Data

I'm trying to setup caching of postcode lookups, which adds the resulting lookup to a text file using the following; file_put_contents($cache_file, $postcode."\t".$result."\n", FILE_APPEND); I'd like to be able to check this file before running a…
user1235285
  • 87
  • 2
  • 17
0
votes
1 answer

HTTP/1.0 405 Method Not Allowed and false with CURL

I'm trying to get some data from that website: https://stubhub.com . 1- With file_get_contents: $url= 'https://www.stubhub.com'; $html = file_get_contents($url); echo $html; I get: Warning: file_get_contents(https://stubhub.com): failed to open…
user9853119
0
votes
0 answers

Download Zip From Different Path using Php

If i have a path like below: "/sites/main/files/myfile.zip" How can I download the file using PHP? I tried something like below but nothing happens. Anyone has any ideas? $myzipfile = "/sites/main/files/myfile.zip"; file_put_contents("myfile.zip",…
CloudSeph
  • 863
  • 4
  • 15
  • 36
0
votes
0 answers

Problem transformation json file to array in php

This is Data recovery from $_POST $list = array(0=>$_POST['matricule'],1=>$_POST['nom'],2=>$_POST['prenom'],3=>$_POST['dn'],4=>$_POST['tel'],5=>$_POST['mail'],6=>$_POST['sexe'],7=>$_POST['adresse']); $contenu_json =…
0
votes
1 answer

In PHP, how to pass session id along with file_get_contents function?

Why does this code cause the website to get stuck: $id = session_id(); $url = 'https://www.website.com/dev/appointment?id='. $id . ''; $data = file_get_contents($url); while everything goes well as planned when replacing $id with the actual…
Durian Nangka
  • 257
  • 4
  • 17
0
votes
2 answers

The Response content must be a string or object implementing __toString(), “boolean”

I have an API , i want to get this API details using file_get_contents using laravel code. But i getting this error "The Response content must be a string or object implementing __toString(), "boolean" given." Here is my code, $context =…
user10493532
0
votes
0 answers

Results from ip-api.com are not returned (finding ISP from IP address)

I am using the below code to receive ISP from given IP address. Till two days ago it worked fine, and I am pretty sure I changed nothing. The API: http://ip-api.com/docs/api:serialized_php I know that Unserialize is deprecated and should use JSON,…
0
votes
1 answer

file_get_content return null for some url

why some url with json content return null on php function get page content? i used these ways : file_get_content curl http_get but return null . but when page open with browser json content show on browser ?? anyone can help me? $url =…
bnnoor
  • 656
  • 2
  • 13
  • 31
0
votes
0 answers

Problem with php and file_get_contents , allow_url_fopen

I have this code i compile in my computer but dont work . I…
0
votes
2 answers

How can I concatenate 2 .json url's?

What function can I use to connect 2 .json data together? Essentially I have: https://api.coinmarketcap.com/v2/ticker/?limit=1&start=1 and https://api.coinmarketcap.com/v2/ticker/?limit=1&start=2 I want to connect the "data" segment together, so it…
Yuri
  • 89
  • 1
  • 1
  • 9
0
votes
1 answer

Trying to print a specific part from a json url

I am trying to grab the "price" of Bitcoin using the script below. Essentially it visits the coinmarketcap api and prints out the price of bitcoin. However, I am unsure as to what this error means or how I can fix it My code
Joey Yue
  • 29
  • 1
  • 4
0
votes
0 answers

Get data from array PHP with no node No's

Good Day, How do I get data from this array ? Array ( [input] => Array ( [account] => XXXXX [mass] => 0.6 [quantity] => 5 [length] => 15 [width] => 15 [height] => 15 [to_town] =>…
Andrew
  • 1
0
votes
1 answer

Variables not being replaced by values in string fetched by file_get_contents()

I have a file where I store multiple templates with a delimiter. I fetch the contents using file_get_contents(), then parse them using preg_match_all(). In these templates I include variables, which I expected to be replaced by their values, as I…
dudah84
  • 19
  • 2
0
votes
0 answers

Get specific part of external URL

I attempted to look this up but I can't seem to find what I need. I have this URL i'm trying to extract data from. I want to get only the uptime percentage for the last 30 days (bottom left). My first idea was to convert the contents of the page to…
Syllith
  • 189
  • 10
0
votes
1 answer

PHP Get 400 error when using file_get_contents with space in URL

I am trying to read an external page, but the problem is the url has a space in it. For example: www.somesite.com/test/main .html You see a space after main. When you go to the URL via the browser the page comes up. But when I try to use PHPs…
John
  • 9,840
  • 26
  • 91
  • 137