I was wondering if there was any way to make a Parser in PHP in which gets the values from this site https://btc-e.com/api/2/btc_usd/ticker
and sets them as variables in php code?
I have looked at php parsers a bit and the only thing I found was parsers that echo all the information on a website.
Since that URL returns a
JSON
response:The data on that page is called Json (JavaScript Object Notation) (its not output as json mime type, but it is formated like json).
If you know that the data will be json, you can aquire it as a string from the page (using for example the
file_get_contents
function) and decode it to an associative array with thejson_decode
function:You can use
file_get_contents
to get the data from the URL andjson_decode
to parse the result, because the site you have linked is returning a JSON array, that can be parsed by php natively.Example:
In the
$bitcoin
variable you will have an associative array with the values of the JSON string.Result: