Is there a JavaScript way to do file_get_contents()?
you could do
JS code:
$.post('phppage.php', { url: url }, function(data) {
document.getElementById('somediv').innerHTML = data;
});
PHP code:
$url = $_POST['url'];
echo file_get_contents($url);
That would get you the contents of the url.
Get file content from URL?
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=250x100&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=250x100&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 the raw JSON data, then simply remove the json_decode
.
Related Topics
How to Emulate an HTML Input "Maxlength" Attribute on an HTML Textarea
HTML Drag and Drop on Mobile Devices
How to Open Specific Tab of Bootstrap Nav Tabs on Click of a Particuler Link Using Jquery
How to Localize a Simple HTML Website Page in My Case
Set Default Value for a Input File Form
Save and Render a Webpage with Phantomjs and Node.Js
How to Remove Youtube Branding After Embedding Video in Web Page
How to Remove a Buggy Service Worker, or Implement a "Kill Switch"
Creating Drop Down Menu on Click CSS
Scroll to Element on Click in Angular 4
Make Checkbox Behave Like Radio Buttons with JavaScript
How to Keep the Menu State on Page Reload
Writing File to Desktop Using HTML5 Filesystem API
Dynamically Using the First Frame as Poster in HTML5 Video
Open Android Application from a Web Page
Scale a Div to Fit in Window But Preserve Aspect Ratio