I’m a php and javascript newbie so don’t be mad.
Ok so i want to get xml file from another server and then extract only one data(number) and put it in javascript variable so i can calculate with it.
I have this code that gets xml file fine, and i get $result variable with data that i need, but i can’t save that data in javascript variable.
The reason i need this number in javascript is because all of calculations are coded in javascript.
this is php code:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,
'http://www.pbz.hr/Downloads/PBZteclist.xml');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xml = curl_exec($ch);
echo($xml);
curl_close($ch);
$xmlObject = new SimpleXMLElement($xml);
$node = $xmlObject->children();
$result = $node[0]->Currency[12]->BuyRateForeign;
echo("<br />");
echo("<br />");
echo $result;
?>
I need data from EUR7,480000
That number 7,480000 is all i need to extract and save in javascript variable.
Maybe the way i’m doing this isn’t right, but i have tryied everything. Please help me.
I would suggest grabbing the value using an xpath, in case the order changes up.
If you want to use as a string, wrap it in quotes. If you are using it in calculations you might need to strip out the commas etc…