Saturday, April 21, 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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...