开发者

I need to store the XML in SERVER through PHP

开发者 https://www.devze.com 2023-01-06 16:20 出处:网络
I need to store the XML that i get it from Google Analytics. Its format is XML file. I need to create the script ( PHP ) that will read XML file from Google Analytics and store in my server with user

I need to store the XML that i get it from Google Analytics. Its format is XML file. I need to create the script ( PHP ) that will read XML file from Google Analytics and store in my server with user defined name. I tried like that

<?php
$dom = new DOMDocument();
$dom->load('https://www.google.com/analytics/reporting/export?fmt=1&id=346044461&pdr=20100611-20100711&cmp=average&a开发者_运维问答mp;rpt=DashboardReport');
$dom->save('books3.xml');
?>

Can you help me


you're not assigning the result of load to anything you can save afterwards. and that is assuming you created a function load.

you'd need something more along the lines of

<?php
$remoteUri = 'https://www.google.com/analytics/reporting/export?...';

$doc = new DOMDocument();
$doc->loadXML(file_get_contents($remoteUri));
$xml = $doc->saveXML($doc->documentElement);
file_put_contents($yourLocalFilePath, $xml);

or if you just want a completely verbatim copy locally:

<?php
$remoteUri = ...

file_put_contents($yourLocalFilePath, file_get_contents($remoteUri));

the second, simpler version doesn't attempt to parse any xml and will therefore not have any clue if something is wrong with the recieved document.

depending on your server, you might have to resort to more complex methods of getting the file if url wrappers for fopen aren't enabled, or if your google endpoint wants to use cookies etc. for example.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号