I am trying to use simpleXML to get data from http://rates.fxcm.com/RatesXML
Using simplexml_load_file() i had errors at times as this website always has weird strings/numbers before and after the xml file.
Example:
2000<?xml version="1.0" encoding="UTF-8"?>
<Rates>
<Rate Symbol="EURUSD">
<Bid>1.27595</Bid>
<Ask>1.2762</Ask>
<High>1.27748</High>
<Low>1.27385</Low>
<Direction>-1</Direction>
<Last>23:29:11</Last>
</Rate>
</Rates>
0
I then decided to use file_get_contents and parse it as a string with simplexml_load_string(), afterwards which I use substr() to remove the strings before and after. However, sometimes the random strings will appear in between the nodes like this:
<Rate Symbol="EURTRY">
<Bid>2.29443</Bid>
<Ask>2.29562</Ask>
<High>2.29841</High>
<Low>2.28999</Low>
137b
<Direction>1</Direction>
<Last>23:29:11</Last>
</Rate>
My question is, is there anyway i can deal with all these random strings at a go with any regex functions regardless of where they are placed? (think that will be a better idea rather than to contact the site to get them to broadcast proper xml files)