How to convert base64 to binary stream in php
This article will explain in detail how to convert base64 to binary stream in php, Xiaobian thinks it is quite practical, so share it with you as a reference, I hope you can gain something after reading this article.
php base64 to binary stream method: 1, create a PHP sample file;2, by "function base64_to_blob($base64Str){...} "method converts the base64 string to a binary stream.
Operating environment: Windows 7 system, PHP 7.1 version, DELL G3 computer.
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'];
The strpos() function finds the first occurrence of a string in another string.
The substr() function returns a portion of a string.
base64_decode -Decode data encoded using MIME base64.
About "php base64 how to binary stream" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.