2016-08-17 83 views
0

我一直在用一些破碎的代碼拉我的頭髮。我提前發佈了一個問題,但是我已經將問題縮小到了具體問題。在PHP中使用base64_decode()後無法讀取字符串變量

前面的問題:Can't assess an array element after building array - a var_dump confirms element is there

現在的問題是與以base64解碼功能。它的意思是返回一個字符串,但是當你試圖讀取字符串時,它不起作用。

參見這個簡單的測試代碼...

的error_reporting(E_ALL);

$encoded = base64_encode('my encrypted text'); 
$decoded = base64_decode($encoded, true); 

echo "<br />"; 
printf('my encrypted text -> encoded to base64 = %s', $encoded); 
echo "<br />"; 
printf('%s from base64 = %s', $endcoded, $decoded); 
echo "<br />"; 
printf('calling $decoded to read string: result = %s', $decoded); 

下面是結果

my encrypted text -> encoded to base64 = bXkgZW5jcnlwdGVkIHRleHQ= 

Notice: Undefined variable: endcoded in /home/website/base64test.php on line 10 
from base64 = my encrypted text 
calling $decoded to read string: result = my encrypted text 

10號線是這樣的:

printf('%s from base64 = %s', $endcoded, $decoded); 

這是一個錯誤?或者我錯過了什麼。

你打算如何在base64_decode()函數存儲在變量中後讀取結果?

+0

'S/endcoded/encoded' – Phil

回答

1

你有一個錯字:恩d編碼:

printf('%s from base64 = %s', $endcoded, $decoded); 
//-------------------------------^ 

應該

printf('%s from base64 = %s', $encoded, $decoded); 
//-------------------------------^ 
+0

謝謝@Phil。顯然堆棧溢出不認爲有一個等寬字體它對移動視圖很重要。直到我看到您的編輯時,我才意識到它有多遠。 –

+0

嘿嘿,我猜它是來自手機 – Phil

-1

檢查錯字的$endcoded

printf('%s from base64 = %s', $encoded, $decoded); 
+1

添加一個與之前的現有答案相同的答案有什麼意義? –

+0

@JonathonReinhart,有添加答案的螞蟻限制,如果已經提供答案是相似的,或者如果任何答案被標記爲接受? –

+1

沒有限制。隨意浪費你的時間和OP的時間,以及被低估。 –