I am trying to use simpleXML to retrieve data from http://rates.fxcm.com/RatesXML Using simplexml_load_file() , I had errors because this site always had strange lines / 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
Then I decided to use file_get_contents and simplexml_load_string() it as a string with simplexml_load_string() , after which I use substr() to delete the lines before and after. However, sometimes random lines appear between these nodes:
<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 handle all these random strings when working with any regular expressions no matter where they are placed? (think it would be a better idea, not contact the site to get them to translate the corresponding XML files)
source share