Search code examples
phppaypalnvp

PHP and NVP (Name-Value Pair) lists?


Working a bit with PayPal and stumbled on the NVP response. I´m used to working with JSON and XML as a response format. But have never worked with the NVP "simplified" format. Why aren´t they and others using JSON/XML instead of NVP?

A list can look like this SomeList.Item(0).name

Is there a good way to work with NVP in PHP?

Hope somebody can explain the pros with NVP over JSON and XML and a way to work with NVP in PHP. Like how to iterate through a list.


Solution

  • you can use PHP's parse_str() function. It parses a string like

    user=test&password=123
    

    into a PHP array in this form:

    Array
    (
        [user] => test
        [password] => 123
    )