Hướng dẫn dùng base64 decrypt trong PHP

[PHP 4, PHP 5, PHP 7, PHP 8]

base64_decodeDecodes data encoded with MIME base64

Description

base64_decode[string $string, bool $strict = false]: string|false

Parameters

string

The encoded data.

strict

If the strict parameter is set to true then the base64_decode[] function will return false if the input contains character from outside the base64 alphabet. Otherwise invalid characters will be silently discarded.

Return Values

Returns the decoded data or false on failure. The returned data may be binary.

Examples

Example #1 base64_decode[] example

The above example will output:

This is an encoded string

winkelnkemper at googlemail dot com

11 years ago

If you want to save data that is derived from a Javascript canvas.toDataURL[] function, you have to convert blanks into plusses. If you do not do that, the decoded data is corrupted:

walf

6 years ago

Base64 for URL parameters/filenames, that adhere to RFC 4648.
Defaults to dropping the padding on encode since it's not required for decoding, and keeps the URL free of % encodings.



for big $encoded strings, it's saver to use



where 256 can be replaced by a sufficiently small modulo 4 natural.

Tom

15 years ago

This function supports "base64url" as described in Section 5 of RFC 4648, "Base 64 Encoding with URL and Filename Safe Alphabet"

   

Starson

15 years ago

To expand on Jes' post:

The change took place between 5.0.5 and 5.1.0.  Exactly where I don't know or care.

In short php

This is the PHP equivalent to perl's unpack["u",___]. That is, you need to strip the 'begin' and 'end' lines from the typical uuencoded file.

Klaus Fehrenbacher

19 years ago

this script can correct the bug

dimagolov at yahoo dot com

13 years ago

Here is function to decode Base 62 [see //en.wikipedia.org/wiki/Base_62] string to number. It is used by MTA in message id, e.g. by Exim

zmorris at zsculpt dot com

14 years ago

Here is a drop-in replacement for base64_decode[], based on a faster version of morgangalpin's code:

alvaro at demogracia dot com

13 years ago

You can do partial decoding [e.g. from buffered input streams] if you choose a chunk length that is multiple of 4:



4 encoded chars represent 3 original chars. The "=" character is used as padding.

markandrewslade at gmail dot com

6 years ago

The docs don't make this explicitly clear, but if you omit `$strict` or set it to `false` then invalid characters in the encoded input will be silently ignored.

Chủ Đề