2016-08-17 84 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的时间,以及被低估。 –