How to convert php base64 to binary stream

藏色散人
Release: 2023-03-12 22:56:01
Original
3281 people have browsed it

php Base64 to binary stream method: 1. Create a PHP sample file; 2. Convert the base64 string into a binary stream through the "function base64_to_blob($base64Str){...}" method.

How to convert php base64 to binary stream

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer.

php How to convert base64 to binary stream?

php base64 string to binary stream

The code is as follows:

function base64_to_blob($base64Str){
    if($index = strpos($base64Str,'base64,',0)){
        $blobStr = substr($base64Str,$index+7);
        $typestr = substr($base64Str,0,$index);
        preg_match("/^data:(.*);$/",$typestr,$arr);
        return ['blob'=>base64_decode($blobStr),'type'=>$arr[1]];
    }
    return false;
}
$data = base64_to_blob($base64Str);
header('Location: '.$data['type']);
echo $data['blob'];
Copy after login

strpos( ) function finds the first occurrence of a string within another string.

The substr() function returns a part of a string.

base64_decode — Decode data encoded using MIME base64.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to convert php base64 to binary stream. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!