Home  >  Article  >  Backend Development  >  Base64_encode and urlencode string encryption methods in php_PHP tutorial

Base64_encode and urlencode string encryption methods in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:10:091203browse

This article introduces the use of PHP's ase64_encode and urlencode to simply encrypt strings. It is also a relatively common method. Students in need can refer to this article.

base64_decode
Decode a BASE64 encoded string.

Syntax: string base64_decode(string encoded_data);

Return value: String

Function type: Encoding processing


Content Description


This function will decode a MIME BASE64 encoded string. The decoded string may be a Chinese string or other binary data.

Example

The code is as follows
 代码如下 复制代码
$str = 'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==';
echo base64_decode($str);
?>
Copy code


$str = 'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==';

echo base64_decode($str);

?>

 代码如下 复制代码
$query_string = 'foo=' . urlencode($foo) . '&bar=' . urlencode($bar);
echo '';
?>

str urlencode($string)

This feature is handy when encoding strings to be used as part of a query in the URL as a convenient way to pass variables to the next page.

I wrote this simple function that creates a GET query for the url() from an array:
 代码如下 复制代码
$encryption = "username";
echo base64_encode ($encryption);//echo "dXNlcm5hbWU= ";
echo "
";
echo urlencode("http://".$encryption);//echo " http%3A%2F%2Fusername ";
echo "
";
echo sha1($encryption);//echo "249ba36000029bbe97499c03db5a9001f6b734ec"
echo "
";
?>
The code is as follows
Copy code

$query_string = 'foo=' . urlencode($foo) . '&bar=' . urlencode($bar);