i got a piece of code that so far returns me data like this when i use print $result;
ssl_card_number=41**********1111
ssl_exp_date=0213
ssl_amount=132.86
ssl_salestax=0.00
ssl_invoice_number=5351353519500
ssl_result=0
ssl_result_message=APPROVED
ssl_txn_id=00000000-0000-0000-0000-00000000000
ssl_approval_code=123456
ssl_cvv2_response=P
ssl_avs_response=X
ssl_account_balance=0.00
ssl_txn_time=11/21/2012 12:38:20 PM
thats from view page source.
and the page itself shows it as :
ssl_card_number=41**********1111 ssl_exp_date=0213 ssl_amount=132.86 ssl_salestax=0.00 ssl_invoice_number=8601353519473 ssl_result=0 ssl_result_message=APPROVED ssl_txn_id=00000000-0000-0000-0000-00000000000 ssl_approval_code=123456 ssl_cvv2_response=P ssl_avs_response=X ssl_account_balance=0.00 ssl_txn_time=11/21/2012 12:37:54 PM
i need to be able to handle each of the “keys” in a better way and dont know how to explode them maybe ?
One possible approach:
Explanation:
preg_replacewill turn all the whitespace before the param names into ‘&’ symbol – making this string similar to the regular GET request url. Thenparse_str(the function created specifically for parsing such urls) will, well, parse this string (sent as the first param), making an associative array of it.In fact, you don’t even have to use preg_replace here, if each param=value string begins from a new line;
str_replace("\n", '&')should do the trick.An alternative approach:
Here you first create an array of ‘key-value pair’ strings, then split each element by
=: the first part would be the key, the second – the value.