1

I have a perfectly working function

    function response( $array ) {

        $response = array();

        $results  = preg_split( '/$\R?^/m', $array );

        foreach( $results as $result ){ 

            $value = explode( '=', $result, 2 );
            $response[trim($value[0])] = trim($value[1]);

        }

        return $response;

    }

But, on one particular site, using PHP 5.3.3, it's not working correctly.

On every other site I've tried it on I get

    Array
    (
[VPSProtocol] => 3.00
[Status] => 3DAUTH
[StatusDetail] => 2007 : Please redirect your customer to the ACSURL, passing the MD and PaReq.
[3DSecureStatus] => OK
[MD] => 201458812600945291
[ACSURL] => https://test.sagepay.com/mpitools/accesscontroler?action=pareq
[PAReq] => eJxVUttygjAQfe9XMHwAuXApOGscqw91Ora2tg/1jYYdwQpogHr5+iYI1eZpz0n27O7ZwOiYb60fVFVWFkObOdQeiTt4TxXidImyUShgjlUVr9HKkqHNKfP8MGQ8oDTyfB4xW8Bi/IZ7AZ2M0CoOA9JDna9kGhe1gFjuH2bPwvMCN/CBdBByVLOp4IzS+/ZQc4BcaCjiHMUkVWWO1ouKizUCaTmQZVPU6iRCHgDpATRqK9K63g0IkW1W2SY5snSabyDmGsi1p0VjokrLHbNEPH1lH5Olf14dXjFa7WtFN7579jfzw+cQiHkBSVyj0D4E1OWeRaOB5w64brflIc5NH4K7UagHvADYmRrj25tbBrTNCgvZD9IjwOOuLNDkAPmLIcFKiqVZyCI+WfPFTJc2FJDrKJNHY7astX/M+NxGRi/TDrGAXQQNAGLekm6FpNu1jv79gV8cl7Rg
    )

but on the 5.3.3 server I get

    Array
    (
        [VPSProtocol] => 3.00
    Status=3DAUTH
    StatusDetail=2007 : Please redirect your customer to the ACSURL, passing the MD and PaReq.
    3DSecureStatus=OK
    MD=2014590184178038623
    ACSURL=https://test.sagepay.com/mpitools/accesscontroler?action=pareq
    PAReq=eJxVUsGOgjAQve9XED+AUhAEM9agJurBDVEvHhuYlW6kYIFV/n5bhdXtad6byZuZN4X5vbhYP6hqUcrZiNrOaM4+4JgrxNUB01Yhgx3WNT+jJbLZyHXo2I8cGo7pJHS8MHC9EYMk3uOVQa/DtIxNgQxQC6g057JhwNPrYvvJxpEbOQ6QHkKBartifuRHrhs4/QPypEHyAtkxRytBri7WUfFMyLO1LIuKyw7IIw9p2cpGdSx0AyADgFZdWN401ZSQ2+1mf+uRsKuMjp2WBRCTB/IaMGlNVGu9u8iYfxKbOInpevN1akTUrFZivQgKKfa3GRBTARlvkGlXAsdzA4uGU9+behMgDx54YQZhYy8y2z4BVKZH/J55Z0CbrlCmwyYDArxXpURd4QL5iyHDOmUHc56Ed9Yu2erWhgLyWmW5Mc6njTaTGtMfkdET2iIa0KegAUBMLenvSfrL6+jfj/gF1Ym44A==
    )

any suggestions or ideas gratefully received - I don't have access to the server to modify PHP but I do have enough access for PHP info etc.

EDIT

The string that I'm starting with always displays with working line breaks, eg

    VPSProtocol=3.00
    Status=3DAUTH
    StatusDetail=2007 : Please redirect your customer to the ACSURL, passing the MD and PaReq.
    3DSecureStatus=OK
    MD=2014590211813198670
    ACSURL=https://test.sagepay.com/mpitools/accesscontroler?action=pareq
    PAReq=eJxVUk1vwjAMve9XVL1OIh8tHUEmiJXDemCqBodtt6y1aCf6QVpGy69fAmWwnPyerWf7OTDvip3zg7rJq3LmshF15/IBNplGXK4xOWiUsMKmUVt08nTmcsr8saCcsQnzmJgET9SVEC/ecC9h0JFGZsSAXKER0EmmylaCSvbP0av0BReUAhkgFKijpRyLseA8oMMDcqGhVAXKTYZOjErvnI1WaV5unbAqalX2QM55SKpD2epeTngA5ArgoHcya9t6SsjxeBx9m5Gwr63OKKkKIDYP5DZgfLBRY/S6PJXRR0c/N6fF4/viK/RPfFKH4bja6iWrZkBsBaSqRWlcCajHA4eJqSemvln+zIMq7CDS94Td9gKgtj0W95l7BozpGsvkuskVAXZ1VaKp4ED+YkixSeTanidWvbOKI9PaUkBuq4Qv1vmkNWYya/o5snq5sYgF7CJoARBbS4Z7kuHyJvr3I34BhBq4kA==

The developer docs I'm using say

Encoding will be as Name=Value fields separated by carriage-return-linefeeds (CRLF).

  • 1
    Please show the raw non-mutated string. – Ohgodwhy Mar 26 '16 at 19:25
  • the line endings may differ and be `\n` or `\r\n` rather than just `\r` – iam-decoder Mar 26 '16 at 19:26
  • 1
    @iam-decoder it's not \r - http://stackoverflow.com/a/2716436/1232318 "There is a little-known special character \R in preg_* regular exceptions that matches all three:" –  Mar 26 '16 at 19:31
  • @Ohgodwhy edited the original question –  Mar 26 '16 at 19:47
  • @Ohgodwhy the developer docs say "Encoding will be as Name=Value fields separated by carriage-return-linefeeds (CRLF)." –  Mar 26 '16 at 19:52

1 Answers1

0

In this case, this worked

function response( $array ) {

    $response = array();

    $results  = preg_split( '#\n(?!s)#', $array );

    foreach( $results as $result ){ 

        $value = explode( '=', $result, 2 );
        $response[trim($value[0])] = trim($value[1]);

    }

    return $response;

}