Line 1... |
Line 1... |
1 |
<?php |
1 |
<?php |
2 |
// +----------------------------------------------------------------------+ |
2 |
// +----------------------------------------------------------------------+ |
3 |
// | PHP Version 4 | |
3 |
// | PHP Version 4 | |
4 |
// +----------------------------------------------------------------------+ |
4 |
// +----------------------------------------------------------------------+ |
5 |
// | Copyright (c) 1997-2004 The PHP Group | |
5 |
// | Copyright (c) 1997-2004 The PHP Group | |
6 |
// +----------------------------------------------------------------------+ |
6 |
// +----------------------------------------------------------------------+ |
7 |
// | This source file is subject to version 3.0 of the PHP license, | |
7 |
// | This source file is subject to version 3.0 of the PHP license, | |
8 |
// | that is bundled with this package in the file LICENSE, and is | |
8 |
// | that is bundled with this package in the file LICENSE, and is | |
9 |
// | available at through the world-wide-web at | |
9 |
// | available at through the world-wide-web at | |
10 |
// | http://www.php.net/license/3_0.txt. | |
10 |
// | http://www.php.net/license/3_0.txt. | |
11 |
// | If you did not receive a copy of the PHP license and are unable to | |
11 |
// | If you did not receive a copy of the PHP license and are unable to | |
12 |
// | obtain it through the world-wide-web, please send a note to | |
12 |
// | obtain it through the world-wide-web, please send a note to | |
13 |
// | license@php.net so we can mail you a copy immediately. | |
13 |
// | license@php.net so we can mail you a copy immediately. | |
14 |
// +----------------------------------------------------------------------+ |
14 |
// +----------------------------------------------------------------------+ |
15 |
// | Authors: Michael Wallner <mike@php.net> | |
15 |
// | Authors: Michael Wallner <mike@php.net> | |
16 |
// | Aidan Lister <aidan@php.net> | |
16 |
// | Aidan Lister <aidan@php.net> | |
17 |
// +----------------------------------------------------------------------+ |
17 |
// +----------------------------------------------------------------------+ |
18 |
// |
18 |
// |
19 |
// $Id: convert_uuencode.php,v 1.7 2005/01/26 04:55:13 aidan Exp $ |
19 |
// $Id: convert_uuencode.php,v 1.7 2005/01/26 04:55:13 aidan Exp $ |
20 |
|
20 |
|
21 |
|
21 |
|
22 |
/** |
22 |
/** |
23 |
* Replace convert_uuencode() |
23 |
* Replace convert_uuencode() |
24 |
* |
24 |
* |
25 |
* @category PHP |
25 |
* @category PHP |
26 |
* @package PHP_Compat |
26 |
* @package PHP_Compat |
27 |
* @link http://php.net/function.convert_uuencode |
27 |
* @link http://php.net/function.convert_uuencode |
28 |
* @author Michael Wallner <mike@php.net> |
28 |
* @author Michael Wallner <mike@php.net> |
29 |
* @author Aidan Lister <aidan@php.net> |
29 |
* @author Aidan Lister <aidan@php.net> |
30 |
* @version $Revision: 1.7 $ |
30 |
* @version $Revision: 1.7 $ |
31 |
* @since PHP 5 |
31 |
* @since PHP 5 |
32 |
* @require PHP 4.0.0 (user_error) |
32 |
* @require PHP 4.0.0 (user_error) |
33 |
*/ |
33 |
*/ |
34 |
if (!function_exists('convert_uuencode')) { |
34 |
if (!function_exists('convert_uuencode')) { |
35 |
function convert_uuencode($string) |
35 |
function convert_uuencode($string) |
36 |
{ |
36 |
{ |
37 |
// Sanity check |
37 |
// Sanity check |
38 |
if (!is_scalar($string)) { |
38 |
if (!is_scalar($string)) { |
39 |
user_error('convert_uuencode() expects parameter 1 to be string, ' . |
39 |
user_error('convert_uuencode() expects parameter 1 to be string, ' . |
40 |
gettype($string) . ' given', E_USER_WARNING); |
40 |
gettype($string) . ' given', E_USER_WARNING); |
41 |
return false; |
41 |
return false; |
42 |
} |
42 |
} |
43 |
|
43 |
|
44 |
$u = 0; |
44 |
$u = 0; |
45 |
$encoded = ''; |
45 |
$encoded = ''; |
46 |
|
46 |
|
47 |
while ($c = count($bytes = unpack('c*', substr($string, $u, 45)))) { |
47 |
while ($c = count($bytes = unpack('c*', substr($string, $u, 45)))) { |
48 |
$u += 45; |
48 |
$u += 45; |
49 |
$encoded .= pack('c', $c + 0x20); |
49 |
$encoded .= pack('c', $c + 0x20); |
50 |
|
50 |
|
51 |
while ($c % 3) { |
51 |
while ($c % 3) { |
52 |
$bytes[++$c] = 0; |
52 |
$bytes[++$c] = 0; |
53 |
} |
53 |
} |
54 |
|
54 |
|
55 |
foreach (array_chunk($bytes, 3) as $b) { |
55 |
foreach (array_chunk($bytes, 3) as $b) { |
56 |
$b0 = ($b[0] & 0xFC) >> 2; |
56 |
$b0 = ($b[0] & 0xFC) >> 2; |
57 |
$b1 = (($b[0] & 0x03) << 4) + (($b[1] & 0xF0) >> 4); |
57 |
$b1 = (($b[0] & 0x03) << 4) + (($b[1] & 0xF0) >> 4); |
58 |
$b2 = (($b[1] & 0x0F) << 2) + (($b[2] & 0xC0) >> 6); |
58 |
$b2 = (($b[1] & 0x0F) << 2) + (($b[2] & 0xC0) >> 6); |
59 |
$b3 = $b[2] & 0x3F; |
59 |
$b3 = $b[2] & 0x3F; |
60 |
|
60 |
|
61 |
$b0 = $b0 ? $b0 + 0x20 : 0x60; |
61 |
$b0 = $b0 ? $b0 + 0x20 : 0x60; |
62 |
$b1 = $b1 ? $b1 + 0x20 : 0x60; |
62 |
$b1 = $b1 ? $b1 + 0x20 : 0x60; |
63 |
$b2 = $b2 ? $b2 + 0x20 : 0x60; |
63 |
$b2 = $b2 ? $b2 + 0x20 : 0x60; |
64 |
$b3 = $b3 ? $b3 + 0x20 : 0x60; |
64 |
$b3 = $b3 ? $b3 + 0x20 : 0x60; |
65 |
|
65 |
|
66 |
$encoded .= pack('c*', $b0, $b1, $b2, $b3); |
66 |
$encoded .= pack('c*', $b0, $b1, $b2, $b3); |
67 |
} |
67 |
} |
68 |
|
68 |
|
69 |
$encoded .= "\n"; |
69 |
$encoded .= "\n"; |
70 |
} |
70 |
} |
71 |
|
71 |
|
72 |
// Add termination characters |
72 |
// Add termination characters |
73 |
$encoded .= "\x60\n"; |
73 |
$encoded .= "\x60\n"; |
74 |
|
74 |
|
75 |
return $encoded; |
75 |
return $encoded; |
76 |
} |
76 |
} |
77 |
} |
77 |
} |
78 |
|
78 |
|
79 |
?> |
79 |
?> |
80 |
|
80 |
|