The gradient function gradient string from to out null string iconv ut

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//The gradient
function gradient($string, $from = '', $to = '') {
$out = null;
$string = iconv('utf-8', 'windows-1251', $string);
//
$to = array(
hexdec($to[0] . $to[1]), // r
hexdec($to[2] . $to[3]), // g
hexdec($to[4] . $to[5]) // b
);
//
$from = array(
hexdec($from[0] . $from[1]), // r
hexdec($from[2] . $from[3]), // g
hexdec($from[4] . $from[5]) // b
);
$levels = strlen($string);
for ($i = 1; $i <= $levels; $i++) {
for ($ii = 0; $ii < 3; $ii++) {
$tmp[$ii] = $from[$ii] - $to[$ii];
$tmp[$ii] = floor($tmp[$ii] / $levels);
$rgb[$ii] = $from[$ii] - ($tmp[$ii] * $i);
if ($rgb[$ii] > 255) {
$rgb[$ii] = 255;
}
$rgb[$ii] = dechex($rgb[$ii]);
if (strlen($rgb[$ii]) < 2) {
$rgb[$ii] = '0' . $rgb[$ii];
}
}
$out .= '<span style="color: #' . $rgb[0] . $rgb[1] . $rgb[2] . '">' . $string[$i - 1] . '</span>';
}
return iconv('windows-1251', 'utf-8', $out);
}
//The end