Trying to run file_get_contents from http://66.85.14.212:7254
Anyone have any suggestions how I could do this to query specific values?
I am getting the value by given code(it's working properly.):-
<?php
$url="http://66.85.14.212:7254/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($data);
echo "<pre>";
print_r($xml);
//for single variable you can write
echo $xml->Name;
?>
Related
This is my code to fetch api
$apiurl = "https://class.cvcngr.in/bigbluebutton/api/create?allowStartStopRecording=true&attendeePW=ap&autoStartRecording=false&meetingID=random-1495797&moderatorPW=mp&name=random-1495797&record=false&voiceBridge=74999&welcome=%3Cbr%3EWelcome+to+%3Cb%3E%25%25CONFNAME%25%25%3C%2Fb%3E%21&checksum=ad1f82091f78ee18673f9c5be36df9eef7860187";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $apiurl);
$response = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($response);
echo $xml;
In the above, I have used an apiurl which stores URL of API. this is my custom API and there is a test API provided by the service provider
$apiurl2 "http://test-install.blindsidenetworks.com/bigbluebutton/api/create?allowStartStopRecording=true&attendeePW=ap&autoStartRecording=false&meetingID=random-9370670&moderatorPW=mp&name=random-9370670&record=false&voiceBridge=79891&welcome=%3Cbr%3EWelcome+to+%3Cb%3E%25%25CONFNAME%25%25%3C%2Fb%3E%21&checksum=0aae50d2d079fd67138a7b266837f6b0112166b5";
Bothe the URL gives the same response but I can get data only when I use apiurl2. when I use the first one there is no response. but when I use in the browser directly there is no issues
It works just fine, the $xml variable is a SimpleXMLElement instance. echo tries to print a string. You can print all of its contents with var_dump($xml) and access its elements directly with an object operator: echo $xml->dialNumber and even loop thru them:
<?php
$apiurl = "https://class.cvcngr.in/bigbluebutton/api/create?allowStartStopRecording=true&attendeePW=ap&autoStartRecording=false&meetingID=random-1495797&moderatorPW=mp&name=random-1495797&record=false&voiceBridge=74999&welcome=%3Cbr%3EWelcome+to+%3Cb%3E%25%25CONFNAME%25%25%3C%2Fb%3E%21&checksum=ad1f82091f78ee18673f9c5be36df9eef7860187";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $apiurl);
$response = curl_exec($ch);
$xml = simplexml_load_string($response);
// var_dump($xml);
// echo 'Dial number: ' . $xml->dialNumber;
foreach ($xml as $key => $value) {
echo "{$key}: {$value}\n";
}
curl_close($ch);
Hello I'm coming from Get JSON object from URL
I tried to get marketCap->usd.
Can anyone tell me what I'm doing wrong please?
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, 'http://coinmarketcap.northpole.ro/api/v5/ZCL.json');
$result = curl_exec($ch);
curl_close($ch);
$obj = json_decode($result);
echo $result->marketCap->usd;
Change echo $result->marketCap->usd; for echo $obj->marketCap->usd;
You have saved the data decoded in $obj.
Last line of your code should be
echo $obj->marketCap->usd;
scraping perticular data from website using php without using any tools,i have tried this code but it is not sufficient-
<?php
$url = 'http://www.google.com';
$output = file_get_contents($url);
echo $output;
?>
you can used curl in php
<?
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.example.com');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec();
curl_close($ch);
?>
where $data contain html of given url
Here is a URL→ https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=snoopy&rsz=1
and this is my php code
<?php
$url = "https://ajax.googleapis.com/ajax/services/search/images?"."v=1.0&q=snoopy";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$body = curl_exec($ch);
curl_close($ch);
$json = json_decode($body);
?>
I wanna echo all of the image urls from its result
(For example: http://img2.wikia.nocookie.net/__cb20110331075248/peanuts/images/6/62/Snoopy.gif )
But I have no idea how to echo them.
Hope someone could help me, thanks!
Maybe like this:
<?php
$url = "https://ajax.googleapis.com/ajax/services/search/images?" .
"v=1.0&q=barack%20obama&userip=INSERT-USER-IP";
// sendRequest
// note how referer is set manually
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, 'http://example.com');
$body = curl_exec($ch);
curl_close($ch);
// now, process the JSON string
$pics = json_decode($body);
$ret='';
if($pics){
foreach($pics->responseData->results as $pic)
$ret .= $pic->url.'<br>';
}
echo $ret;
?>
in order to echo the exact result just use:
echo $body; //echoes json string
if you want to echo the exact link, echo like this:
echo $json->responseData->results[0]->url; //echoes http://img2.wikia.nocookie.net/__cb20110331075248/peanuts/images/6/62/Snoopy.gif
or you can foreach() twice (or once...) then echo $res->url directly :) your choise!
I want to read XML data from a URL. I have the URL as follows:
http://www.arrowcast.net/fids/mco/fids.asp?sort=city&city=&number=&airline=&adi=A
Here is my code:
$Url="http://www.arrowcast.net/fids/mco/fids.asp?sort=city&city=&number=&airline=&adi=A";
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $Url);
$output = curl_exec($ch);
$resultCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Close the cURL resource, and free system resources
curl_close($ch);
Could anyone please tell me how to read xml data?
Here is some sample code (XML parsing module may not be available on your PHP installation):
<?php
$url="http://www.arrowcast.net/fids/mco/fids.asp?sort=city&city=&number=&airline=&adi=A";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url); // get the url contents
$data = curl_exec($ch); // execute curl request
curl_close($ch);
$xml = simplexml_load_string($data);
print_r($xml);
?>
The variable $xml now is a multi-dimensional key value array and you should easily be able to figure out how to get the elements from there.
// the SAX way:
XMLReader myReader = XMLReaderFactory.createXMLReader();
myReader.setContentHandler(handler);
myReader.parse(new InputSource(new URL(url).openStream()));
// or if you prefer DOM:
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new URL(url).openStream());
This is the demo of how to get channel id from rss feed of youtube in which i read xml data from url using curl.
$channel_id = 'XXXXXXXX'; // put the channel id here
//using curl
$url = 'https://www.youtube.com/feeds/videos.xml?channel_id='.$channel_id.'&orderby=published';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$response = curl_exec($ch);
curl_close($ch);
$response=simplexml_load_string($response);
$json = json_encode($response);
$youtube= json_decode($json, true);
$count = 0;
if(isset($youtube['entry']['0']) && $youtube['entry']['0']!=array())
{
foreach ($youtube['entry'] as $k => $v) {
$yt_vids[$count]['id'] = str_replace('http://www.youtube.com/watch?v=', '', $v['link']['#attributes']['href']);
$yt_vids[$count]['title'] = $v['title'];
$count++;
}
}
else
{
$yt_vids[$count]['id']=str_replace('http://www.youtube.com/watch?v=', '', $youtube['entry']['link']['#attributes']['href']);
$yt_vids[$count]['title']=$youtube['title'];
}
echo "<pre>";
print_r($yt_vids);