Saturday, 21 April 2018

php - Using file_get_contents and use specific parts of the content

I'm trying to get some exchange rates from another website, I'm logging in and grabbing all the data with file_get_contents, this is what I use:



$username = 'myusername@gmail.com';
$password = 'mypassword';
$url = 'http://website-i-get-content-from.com';
$context = stream_context_create(array(
'http' => array(
'header' => "Authorization: Basic " . base64_encode("$username:$password")
)

));
$data = file_get_contents($url, false, $context)

?>


Now I only need some parts of that website: the exchange rates for EUR CHF and GBP, in the source code it looks like this:



EURUSD 0.599USD 0.599


CHFUSD 0.470USD 0.470

GBPUSD 0.675USD 0.675


So 0.599, 0.470 and 0.675 are the numbers I need at this time. They do change obviously.



How do I put them into variables ?

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...