how to parse response from cellcom using that url? - php

I am trying to read this url from my php script:
http://test.cellpay.com.np:8181/cellcom?FN=123&fromMobile=01670746301&phoneNumber=01670746301&PIN=123456&amount=0
please load the url first, check the response and tell me what to do.
I tried the following:
file_get_contents
simplexml_load_string
simplexml_load_file
CURL
failed in all cases.
I've saved the xml and upload it to
http://vtopup.tk/1.xml
I can read this, but not the original one.
Please help me. I am tired of searching and applying...
Thanks.

Tested and it's working.
<?php
$url = 'http://test.cellpay.com.np:8181/cellcom?FN=ATW&fromMobile=testuser&phoneNumber=01670746301&PIN=z2ag&amount=0';
$xml = simplexml_load_file($url) or die("feed not loading");
var_dump($xml);

!!!!!!!!!Finally solved!!!!!!!!!
Thats all about php versions
I was trying from PHP 5.4.27, doesn't work....
Finally tried from PHP 5.6.3 and it works. so simply and magically.
Thanks to Veenex and file_get_contents returns empty string
for all effort.
Thank you guys, thank you very much.

Related

How to create a XML File From Server Response (PHP)

I have a response that I got from a server using PHP, it is returned in XML format. Unfortunately I cannot disclose the code that is in question since it is for a client, but here is a shortened version of it:
// server request code here…
$result = $soap>__doRequest($xmltosend,URL,$action,1); //the final part of the request process…
// $result is the returned xml that is to be converted into a separate file
Is there any way that I could take the returned XML and make a new file? If you have any questions I will be more than happy to answer them!
Thanks in advance!
Try it with DOMDocument:
$doc = new DOMDocument();
$doc->loadXML($result);
$doc->save("/tmp/your-document.xml");
You can find more on this in the php documentation

Blank results on json parse on https api calling using php and MAMP

I´m trying a very simple php script which is about calling a json data through api calling on a online https link using MAMP.
However if I use the following code I have blank results:
<?php
$cnmkt = "https://api.coinmarketcap.com/v1/ticker/?limit=50";
$json = file_get_contents($cnmkt);
$fgc = json_decode($json,true);
echo $fgc[1]['percent_change_7d'];
?>
But if i copy/paste the content of the https link into a test.json file locally, substituting the https link with the test.json file on $cnmkt variable, the same exact script works properly.
I know i´m missing something very obvious, if someone could help me that would be very much appreciated, thanks.
Stefano
The script is working fine. I get an expected result of 4.63
Disable your AV/firewall and check again.

URL not executed in file_get_contents();

I need to execute a URL in back-end, when ever the page executes, for this I am using file_get_contents(); but sadly it is not processing the url requested, please help me, pardon me if I am wrong, thank you.
.PHP
<?php
$url="http://www.foo.in/bound/bound.php?phone_no=".$from_id."&api_key=xxxxxxxxxxxxxxxxxxxx &bound_version=2&extra_data=<response><dial record='true' limittime='1000' timeout='30' moh='default' >".$to_id."</dial></response>";
$data = file_get_contents($url);
?>
I resolved out the solution there was a gap in URL there was space after api_key and extra_data not encoded, btw thanks for support.
.PHP
$url="http://www.foo.in/bound/bound.php?phone_no=".$from_id."&api_key=xxxxxxxxxxxxxxxxxxxxx=2&extra_data=".urlencode("<response><dial record='true' limittime='1000' timeout='30' moh='default' >".$to_id."</dial></response>");
$data = file_get_contents($url);
echo $data;

get data from xml url using php

I am trying to get data from xml url using php but its not working for me. Please check what is wrong in my code.
$result_xml = simplexml_load_file(
"https://maps.googleapis.com/maps/api/geocode/xml?address=UB67JJ"
);
echo $result_xml->GeocodeResponse->result->formatted_address;
I want to get "formatted_address" from xml file.
Don't know where the GeocodeResponse comes from, but it is not in the XML response.
It should just be
echo $result_xml->result->formatted_address;
See https://developers.google.com/maps/documentation/geocoding/
If i remember right, the $result_xml already referes to the outer xml-container, so try:
echo $result_xml->result->formatted_address;

Is it possible to use DOMDocument::load() function to load an rss feed that is an ashx file?

I'm trying to load the contents of what should be an rss feed in a .ashx file on a client's site. I'm not sure if this is possible. Here is the code I'm using.
$doc = new DOMDocument();
$doc->load($client_url);
echo htmlentities($doc->saveXML());
All that is being echoed is <?xml version="1.0"?> which I believe is being created from the saveXML() function.
Any help?
Thanks,
Caleb
I've found the problem thanks to hakre and looking at the errors. The problem was that I was using 'https' in $client_url when I should use 'http'.
Thanks for the advice in turning on my error messages. I think this will be very useful in the future as well.

Categories