2012-06-04 18 views
2

我正在接收一個數組以響應請求。當我做print_r時,這就是我得到的Array([receiver] => {:email=>"[email protected]"})解析我無法識別爲Object或Array或Json的字符串

我無法理解如何訪問「:email」的值。

請幫忙。

編輯:

下面是響應的後續代碼var_dump。

array ('receiver' => '{:email=>"[email protected]"}') 

謝謝。

+1

你可以張貼'的var_dump($ yourarray)'的輸出? – bfavaretto

+0

查看@Pateman對Mike B的回答的評論。你有什麼是字符串'{:email =>「[email protected]」}',所以你必須自己解析它。 – bfavaretto

+0

因爲我假設你的數據結構,所以我放棄了我的答案。祝你好運! –

回答

2

使用正則表達式來獲取電子郵件。

$arr = array('recebodor' => '{:email=>"[email protected]"}'); 

$email = preg_replace('/{:email=>"([^"]+)"}/', '$1', $arr['recebodor']); 
echo $email; // [email protected] 

說明:

{:email=> Match with the "{:email=>" in the string 
"([^"]+)" Get any character within double quotes 
}   Match with the last "}" 
$1   Replace all text with the text found inside parentheses 
+0

好的。謝謝。但不是「:電子郵件」應該是一些數據結構的一部分?我們應該可以通過遍歷或其他方式訪問它? –

+0

@Vivek查看我編輯的代碼。 – flowfree

+0

@bsdnoobz我編輯了你的答案的電子郵件地址。這種事情在StackOverflow上被認爲是垃圾郵件。 – bfavaretto

相關問題