我正在尋找一種簡便地提取包含多個鍵的字符串的方法。該字符串的結果形成一個捲曲頭響應從包含多個鍵的字符串中提取鍵
echo $response['body'];
// status=2 reason=Invalid tariff/currency
期望的結果:
$status == '2';
$reason == 'Invalid tariff/currency';
或
array (
[status] => '2'
[reason] => 'Invalid tariff/currency'
)
這實際上取決於您可以如何很好地預測該數據的形式......例如,如果鍵 - 值對總是由空格分隔並且使用等號運算符分配,則可以使用簡單的preg_match應該解析出來。 –
鏈接http://stackoverflow.com/questions/4923951/php-split-string-in-key-value-pairs http://php.net/manual/en/function.parse-str.php – Uttara