Load xml gzipped from external link - php

I need to load a gzipped xml from an external link but I don't know how to do it.
Now I'm loading this xml file to my server and then I change every 3 days the xml adress in the variable.
The code I'm using now for loading xml is this:
$xmlFile= new SimpleXMLElement('xml/abcd_201407281213_12074_28203833.xml', 0, true);
The link gived to me to download the xml file from their server is like this:
http://nameofthewebsite.com/folder/28203833C78648187.xml?ticket=BA57F0D9FF910FE4DB517F4EC1A275A2&gZipCompress=yes
Someone can help me please?

Related

PHP: save a file (generated by aspx) to server

I have an url provided by a wholesaler. Url generates xml file which I need to save on my server.
I use PHP - file_get_contents and file_put_contents to do that:
$savepath = "path_to_my_server_folder";
$xmlurl = "http://usistema.eurodigital.lt/newxml/xmlfile.aspx?xml=labas&code=052048048048051057049050048049052";
file_put_contents($savepath.'eurodigital.xml', file_get_contents($xmlurl));
File is generated on my server, but its content is empty. I have no problems with other xml files if I provide direct xml url, but in this situation file is generated by aspx file dynamically. Xml url is actual url I use. When I open xmlurl in browser, xml file gets saved to device.
Can you help me with moving xml to my server? What function should I use? Is it even possible to do that using PHP 5? "allow_url_fopen" is ON.
Thank you in advance!

How to Download XML File from a web service with HTML like code

I am new to PHP. I am downloading an XML file from a web service using PHP. I can download the file using this code:
$sourcefile = "http...com?querystring=string";
$destinationfile = 'data\description.xml';
$xml = file_get_contents($sourcefile);
file_put_contents($destinationfile, $xml);
But when I open the XML file, it has < where < should be and > where > should be.
I added this line of code to decode it before saving it to file, which fixes the above problem:
$xml = html_entity_decode($xml);
This doesn't seem to me to be the right way to go about it. Also, I am getting a weird piece of text showing up in the XML file, which prevents me from parsing the XML file:

I tried using str_replace($xml) right before decoding it (and tried it after decoding it), but that wouldn't get rid of it.
What is the correct way to download an XML file using GET from a web service in PHP and will it get rid of that weird string ()?

DOMDocument - Directly load XML file from php://input

Currently I have a PHP file that reads posted XML and then converts/outputs it to JSON. This file looks like this:
<?php
file_put_contents('myxmlfile.xml', file_get_contents('php://input'));
$xmldoc = new DOMDocument();
$xmldoc->load("myxmlfile.xml");
$xpathvar = new DOMXPath($xmldoc);
// Etc etc, for the purpose of my question seeing the rest isn't necessary
// After finishing the conversion I save the file as a JSON file.
file_put_contents('myjsonfile.json', $JSONContent);
?>
The data I'm receiving comes in XML format. To convert it I'm currently saving it as an XML file, and then immediately after creating a new DOMDocument() and loading it in. My question is, is there any way I can cut out the middle man and just load in the XML directly using file_get_contents()?
Ideally it would be this (didn't work):
$xmldoc->load(file_get_contents("php://input"));
If anyone could help me do this I'd really appreciate it!
Thanks
To load from string, instead of filename, use loadXML method.
$xmldoc->loadXML(file_get_contents("php://input"));

Does an RSS feed have to be an XML file?

I ask this because I see only two xml files in a wordpress blog, wlwmanifest.xml and default.xml and neither look like an rss feed. However I do see a php file called feed-rss2.php that looks like an rss feed. Everything I've ever read says that rss feeds have to be xml files. Am I wrong? Can they be php files with xml code inside?
They are just outputting XML code with XML headers. The actual file doesn't have to be an XML file, just the response has to be text/xml and contain XML output. You can do the same for things like CSS files... anything really.
There is no such thing as a file extension in HTTP.
A client requests a URI from a server. The server responds with a Content-Type HTTP header that says what type of file it is sending back, and the file in the HTTP body.
The client doesn't care (and can't know) if the server generated that response by reading a static file, by running a program, or by some other means.
There is no difference to the client between a PHP program that outputs XML and a static XML file.
The RSS Readers would be looking only on the client side, not the server side. In the wordpress installations, the feed-rss2.php is a PHP File, processed by the server, by giving the correct headers in the format:
header("Content-type: text/xml");
So that the readers get to know that it is a XML file and not a PHP file. As Robbo said, the actual file doesn't have to be an XML file, just the response has to be text/xml and contain XML output.
Even the same case with the styles. If you see the wordpress's style.php, it would have something like:
header("Content-type: text/css");
include($theme . "/style.css");
So that, it uses PHP's power to read the appropriate file and display the output in the same URL. Easy isn't it?

PHP Print Included XML File

I'm trying to echo out an XML File via a PHP File. Like so:
Url visits viewxml.php?id=1
Php open a specific XML file, such as "xmlfile_".$_GET['id'].".xml" and prints it as if they are visiting the xml file itself.
The reason I'm using PHP is to do Session checks to make sure they are allowed to view the xml file.
This is how I am doing this:
header("Content-type: text/xml; charset=utf-8");
// send the saved XML file.
include "xmlfile_".$id.".xml";
Doing this gives me the following GC XML error:
And there is nothing below it.
I have tried different approaches, such as printing it or turning it into a string but then I have problems reading the XML on certain software. I am hoping one of you can help me.
Thanks!
include() will attempt to evaluate the file; if there's something in there that looks like PHP then it will corrupt your results.
Try using readfile instead; this will only output the file contents.

Categories