Hi.
I´m pretty new in PHP, i´m having some issues in putting together what i want from a XML.
xml example
<?xml version="1.0" encoding="UTF-8" ?><channel>
<item><title>Hello</title><asd:qw>38.77</asd:qw><asd:za>40.08</asd:za><ttt:toint>-27.064 -177.623</ttt:toint></item>
<item><title>bye</title><asd:qw>38.77</asd:qw><asd:za>40.08</asd:za><ttt:toint>-27.064 -177.623</ttt:toint></item>
</channel>
-Download a file from url. I use this code that works.
<?php
$url = 'http://www.hello.com/test.xml';
$path = 'test.xml';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
file_put_contents($path, $data);
?>
-Replace 2 words, basically i want to remove the ":" from "asd:qw" and "asd:za" fields. But using this code i dont know how to replace two words from the same file..
<?php
// open to read and modify
$file = "test.xml";
$fh = fopen($file, 'r+');
$data = fread($fh, filesize($file));
$data = str_replace("asd:qa", "asdqa", $data);
fclose($fh);
// Open to write
$fh = fopen($file, 'r+');
fwrite($fh, $data);
fclose($fh);
?>
-Split XML field and create two new fields;
From <ttt:toint>-27.064 -177.623</ttt:toint>, i which to split "ttt:toint" from the "space" that separate the two sets of numbers and create two new fields .
ex:
<ttt:toint>-27.064 -177.623</ttt:toint>
<zz>-27.064</zz><aa>-177.623</aa>
And finally i wish to run all in one file (if possible).
I´ve been battling with this issues for some days but my programming skill are pretty green..
Thanks.