So im trying to make a connection with steam api and my site.Steam api returns format in XML, so i have created a connection via PHP to my server using simplexml.it is something like this:
$xml=simplexml_load_file("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=xxxxxxx&steamids=xxx&format=xml");
print $xml->response->players->player->steamid;
And the xml file code is :
<response><players><player><steamid>xxxx</steamid></response></players></player>
So in return I get nothing while i should get this number: xxxx
Also I can get whole document with print_r($xml); but taking only some tags seems not to work
Any tips?
Thanks in advance
Related
I just learned soap a month ago and managed to get a reply in PHP. I managed to get a response and parse it but I am stuck with a different response where I get 5 instead of 1. Trying to figure out how to parse it. I'm so used to arrays and all that it's a bit confusing for me
Here is a normal response/reply
$value = $client->GetInmate($parameters);
$xml = $value->GetInmateResult;
print "Street: ".$xml->Address->Street;
print "<br>City: ".$xml->Address->City;
print "<br>State ".$xml->Address->State;
This works
Now I am trying to do something similar but my same method is not working, here is an image of the structure of the next reply:
http://i.stack.imgur.com/wWFxg.png
As you can see, I'm trying to get the 'Charges (5)' and manage them independently but racking my brain to do so. simplexml_load_string() isn't helping either, doesn't seem to parse them correctly.
Aren't you able to retrieve the result in the loop because it is the same format which i can see in the image attached. If not, then let me know the response which you are getting through this line:
$xml = $value->GetInmateResult
Im trying to pull this data into PHP, ultimately get it into Javascript so I can make some graphs.
When I download the data using cURL from my mac terminal, I open it in xCode and it looks exactly as expected. No issues accessing the website for data:
curl "http://www.treasury.gov/resource-center/data-chart-center/interest-rates/pages/XmlView.aspx?data=yieldyear&year=2015" > test.xml
open test.xml
When I try to pull into PHP, the xml looks very different. For example, the d:BC_1MONTH tag just isn't present:
$url = "http://www.treasury.gov/resource-center/data-chart-center/interest-rates/pages/XmlView.aspx?data=yieldyear&year=2015";
$xml = simplexml_load_file($url);
print_r($xml);
How do i use php to get XML data in the same format as it is on the website and with cURL download?
print_r() doesn't work as expected with SimpleXMLElement objects. You should do this instead: echo $xml->asXML()
When I did that with your code above I saw the element you were asking about.
I was trying to parse the rss of the tag PHP, from http://stackoverflow.com and tried to use something other than DOM Model, So I looked into SimpleXML. THis is my code:
<?php
error_reporting(-1);
$xml = file_get_contents('https://stackoverflow.com/feeds/tag/php');
$loaded = simplexml_load_string($xml) or die("There is a problem");
$str1 = $loaded["entry"]["entry"][0]->title;
echo $str1;
?>
But nothing is displayed on the screen, and also no error is displayed!
The sample data from https://stackoverflow.com/feeds/tag/php can be found at
http://gourabt2.cloudapp.net/sample-data/sample_data.xml
Any Help would be very much appreciated! Thanks! Cheers!
You use array-access in SimpleXML to access attributes so:
$loaded["entry"]
returns the attribute named "entry" from the document element.
use arrow-access to get the element named "entry" instead:
$loaded->entry
this returns the element named "entry".
Additionally take care with namespaces. Parsing a feed with SimpleXML has been outlined already in existing Q&A material, please relate to it.
Try this out.
<?php
$xml = file_get_contents('http://stackoverflow.com/feeds/tag/php');
$loaded = simplexml_load_string($xml) or die("There is a problem");
foreach($loaded->entry as $post) {
echo $post->title . "\n";
}
Output:
join 2 tables - group by id order by date price asc
using php variable in an sql query
Clear browser cache memory by php code
There is a error in parsing the rss from stackoverflow.com. using SimpleXML in PHP
Modify Laravel Validation message response
chained dropdown from database
Php database handling
How to load model with Codeigniter Webservice - Nusoap Server?
multiple report download php adwords api
Unable to confirm Amazon SNS subscription for SES bounces
Comparing if values exist in database
Better way to CURL to WCF
PHP SaaS Facebook app: Host Page Tab ID and User ID
PHP and Mysql - running over PDOStatement
How to change form textbox value in Zend form annotation?
connect Android with PHP, MySQL , unfortunately app has stopped in android emulator
Auto increment a SESSION key ID
Call PHP function in a class from a HTML form
PHP SQL Preventing Duplicate User names: Catching Exception vs Select Query
I am only able to grab the first group of text in between the tr need helping fixing my code
How to run an external program in php
How to connect to php in android using an async task?
PHP Return HTML (Laravel / Lumen Framework)
prestashop smarty if statement
Cakephp OR condition Implementation
Progress bar HTML5/PHP
preg_match file url from jwplayer
Does Cloudflare Cache HTML5 Video Embedded on PHP Page?
how to INSERT INTO JOIN
PHP web service returns "403 forbidden" error
That's because you have the wrong path. Here is the correction.
(string)$loaded->entry->title;
I'm trying to retrieve an webpage that has XML data using file_get_contents().
$get_url_report = 'https://...'; // GET URL
$str = file_get_contents($get_url_report);
The problem is that file_get_contents gets only the secure content of the page and returns only some strings without the XML. In Windows IE, if I type in $get_url_report, it would warn it if I want to display everything. If I click yes, then it shows me the XML, which is what I want to store in $str. Any ideas on how to retrieve the XML data into a string from the webpage $get_url_report?
You should already be getting the pure XML if the URL is correct. If you're having trouble, perhaps the URL is expecting you to be logged in or something similar. Use a var_dump($str) and then view source on that page to see what you get back.
Either way, there is no magic way to get any linked content from the XML. All you would get is the XML itself and would need further PHP code to process and get any links/images/data from it.
Verify if openssl is enable on your php, a good exemple of how to do it:
How to get file_get_contents() to work with HTTPS?
I'm having trouble figuring out what my Flex Project is expecting from my PHP file in-relation to HTTP Service. Can anyone give a link or an example as to what the PHP file should return? I already configured the return type of the Operation to String. Then on my PHP file, I put in a simple line of code
<?php
echo "hello world";
?>
but the problem is, whenever I try to test the Operation, Flash Builder keeps telling me InvocationTargetException:The response is not a valid XML or a JSON string
I want to see a working example of interactions between a Flex Project and an HTTP Service...
Flash Builder expects an XML or JSON as a result.
So in your php file you'll have to wrap the result as a XML (or JSON):
<?xml version="1.0"?>
<theresult>
<thestring>hello world</thestring>
</theresult>