简体   繁体   中英

How to decode safely base64?

i have some base64 encoded articles in a big SQL.

i need to decode these articles and echo them.

my problem is that they seems to be in binary, wich is a little bit risky and i can't echo them after doing a base64_decode()

how can i convert them into safe text?

EDIT : seems i am not clear enough,

1) Sorry about my title, english is my 2nd language and i have no clue how to ask it rightm if someone can edit i would appreciate it.

2) i don't know what kind of binary code it is, i think it's linked to the fact it's stored as LONGTEXT format in my MYSQL DB. the only answers i found were with n2lbr() but it's already some html so i don'T want a bunch of <br /> to mess with my things.

I HAVE TRYED THINGS LIKE :

preg_replace('#\n\r#', ' ' ,$data);
preg_replace('#\n#', ' ' ,$data);
preg_replace('#\r#', ' ' ,$data);
str_replace('\n\r', ' ' ,$data);

After decoding, I think mb_detect_encoding() would be a good command to see if it needs a charset conversion (iconv or utf8_encode).

http://se2.php.net/manual/en/function.mb-detect-encoding.php

If possible, convert your mysql columns to text or varchar and use ie "set character set utf8" when opening a db connection.

After decoding you'll need to either output them to file or to the browser with the proper mime type. If you don't know the mime type you use the Fileinfo commands to find the mime type:

$content = base64_decode($yourdata);
$finfo = new finfo;
$mimeType = $finfo->buffer($content, FILEINFO_MIME);

Then you can use the mime type to send the proper header to the browser based on the file data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM