PHP URL函数

PHP base64_decode() 函数对使用 MIME(多用途互联网邮件扩展)编码的给定字符串进行base解码。

语法

base64_decode(string, strict) 

参数

string必填。 指定编码字符串。
strict可选。 如果设置为 true,则当字符串 包含 base64 字母表之外的任何字符时,该函数将返回 false。否则,无效字符将被默默丢弃。默认为 false。

返回值

返回解码后的数据,失败时返回 false。返回的数据可能是二进制的。

示例:

下面的示例显示了base64_decode()函数的用法。

<?php
$str = "WXhqYzEyMw==";
$decoded_str = base64_decode($str);

//显示解码后的字符串
echo $decoded_str;
?> 

上述代码的输出将是:

Yxjc123 

示例:

再考虑一个示例,它显示了字符串的编码方式以及使用 MIME base64 进行解码。

<?php
$str1 = "Programming is fun";
$encoded_str1 = base64_encode($str1);

echo "The string is: $str1 \n";
echo "Encoded string is: $encoded_str1 \n";

$str2 = "UHJvZ3JhbW1pbmcgaXMgZnVu";
$decoded_str2 = base64_decode($str2);

echo "\nThe string is: $str2 \n";
echo "Decoded string is: $decoded_str2 \n";
?> 

上述代码的输出将是:

The string is: Programming is fun 
Encoded string is: UHJvZ3JhbW1pbmcgaXMgZnVu 

The string is: UHJvZ3JhbW1pbmcgaXMgZnVu 
Decoded string is: Programming is fun