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:
<?php
$encodedData = str_replace(' ','+',$encodedData);
$decocedData = base64_decode($encodedData);
?>
PHP.mk документација
base64_decode
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
Патека
function.base64-decode.php
Локална патека за оваа страница.
Извор
php.net/manual/en
Оригиналниот HTML се реупотребува и локално се стилизира.
Режим
Прокси + превод во позадина
Кодовите, табелите и белешките остануваат читливи во истиот тек.
Референца
function.base64-decode.php
base64_decode
Референца за `function.base64-decode.php` со подобрена типографија и навигација.
base64_decode
(PHP 4, PHP 5, PHP 7, PHP 8)
base64_decode — Decodes data encoded with MIME base64
= NULL
Декодира податоци кодирани со MIME base64 string.
Параметри
Вратени вредности
ако влезот содржи карактери од надвор од base64 азбуката. Инаку, неважечките карактери ќе бидат тивко отфрлени. false Враќа декодирани податоци или
Примери
Пример #1 base64_decode() example
<?php
$str = 'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==';
echo base64_decode($str);
?>Пример #1 Пример што покажува затворачка ознака што го опфаќа последниот нов ред
This is an encoded string
Белешки од корисници 4 белешки
при неуспех. Вратените податоци може да бидат бинарни. ¶
пред 15 години
walf ¶
пред 10 години
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.
<?php
function base64url_encode($data, $pad = null) {
$data = str_replace(array('+', '/'), array('-', '_'), base64_encode($data));
if (!$pad) {
$data = rtrim($data, '=');
}
return $data;
}
function base64url_decode($data) {
return base64_decode(str_replace(array('-', '_'), array('+', '/'), $data));
}
winkelnkemper на googlemail точка ком ¶
пред 16 години
I had some trouble trying to let base64_decode decode base64-strings longer than ~5k chars.
The base64-decoding function is a homomorphism between modulo 4 and modulo 3-length segmented strings. That motivates a divide and conquer approach: Split the encoded string into substrings counting modulo 4 chars, then decode each substring and concatenate all of them.
Then instead of
<?php $decoded = base64_decode($encoded); ?>
for big $encoded strings, it's saver to use
<?php
$decoded = "";
for ($i=0; $i < ceil(strlen($encoded)/256); $i++)
$decoded = $decoded . base64_decode(substr($encoded,$i*256,256));
?>
where 256 can be replaced by a sufficiently small modulo 4 natural.
7 белешки ¶
19 години пред
This function supports "base64url" as described in Section 5 of RFC 4648, "Base 64 Encoding with URL and Filename Safe Alphabet"
<?php
function base64url_decode($base64url)
{
$base64 = strtr($base64url, '-_', '+/');
$plainText = base64_decode($base64);
return ($plainText);
}
?>