[原]php的base64解码函数
Posted by bianbian on 2007-03-19 04:22
调用 base64_decode() 就行了。
我承认我很BT地觉得是不是php的这个函数有问题,导致我原先提到的问题产生:php处理base64编码和Unicode客户端交互的问题
于是我照着某文档,重新实现了一下。结果发现是一样的(废话)。-___-!!
我承认我错了,当然前面那个问题不是php的原因。不过既然已经写了,我就贴一下吧。至少base64解码俺是会了。哈哈,对了,还有C语言实现的base64解码,下次也来贴一下。
- //php功能等同于base64_decode(),所以没有任何实际用途
- function my_base64_decode(&$str)
- {
- $Bstr_base64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
- $len = strlen($str);
- if ($len % 4 !=0)
- return '';
- $res = $bins = '';
- for ($i = 0; $i < $len; $i++)
- {
- $nChar = substr($str, $i, 1);
- if ($nChar == '=')
- break;
- $oldValue = strpos($Bstr_base64, $nChar);
- $binValue = substr('000000' . decbin($oldValue), -6);
- $bins .= $binValue;
- if (strlen($bins) >= 8)
- {
- $deChar = substr($bins, 0, 8);
- $bins = substr($bins, 8);
- $res .= chr(bindec($deChar));
- }
- }
- return $res;
- }
遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道
March 19th, 2007 at 05:57:05
我想请教一下您是用什么方法贴代码以及用什么程序看php代码的呢?
我最近要读php 代码,没找到顺手的工具。
March 19th, 2007 at 06:24:42
你是说贴到blog里吗?我用的是WP的插件coolcode。
编写php代码我老土了,用的是UltraEdit。不过听说有专门的Zend Studio,还有PHP Edit之类的。不过我已经习惯UltraEdit了,呵呵。
April 3rd, 2007 at 06:32:42
net最近写这么多php的文章