I have a problem in using PHPXPath to fetch exchange rates based on the country of a logged-in client.
For reference: PHP XPath is a php class for searching an XML document using XPath.
I have a database with all the clients nations and associated currency values.
The code I'm using so far to fetch the rates (from ECB feed) is this:
$Rates = new XPath();
$Rates->importFromFile("http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml");
$userRate = $Rates->getAttributes("//Cube[@currency='USD']","rate");
Now, what I want is to pass a variable as the currency value (USD in the example above). My problem is, since I'm completely new to XPath, is the syntax to do that. Assuming the variable name is
$user_data->GRUPPO_005
I've tried the following solutions, but I keep getting "UNEXPECTED T_VARIABLE" error:
$userRate = $Rates->getAttributes("//Cube[@currency='"$user_data->GRUPPO_005"']","rate");
$userRate = $Rates->getAttributes("//Cube[@currency='".$user_data->GRUPPO_005."']","rate");
$userRate = $Rates->getAttributes("//Cube[@currency='.$user_data->GRUPPO_005.']","rate");
I think this is because of my scarce knowledge of the language, I'd love a small hint of this.