Php de degrade yazı yazmak

Php de degrade yazı  yazmak
<?php
function gradient_text($str, $color1, $color2, $html=’span’){
$color1 = str_replace(‘#’, ”, $color1);
$color2 = str_replace(‘#’, ”, $color2);
$color1 = strlen($color1) === 3 ? $color1{0} . $color1{0} . $color1{1} . $color1{1} . $color1{2} . $color1{2} : $color1;
$color2 = strlen($color2) === 3 ? $color2{0} . $color2{0} . $color2{1} . $color2{1} . $color2{2} . $color2{2} : $color2;
$endstr = ‘<‘ . $html . ‘ style=”color:#’ . $color1 . ‘;”>’ . $str{0} . ‘</’ . $html . ‘>’;
$colors[0] = hexdec(substr($color2, 0, 2));
$colors[1] = hexdec(substr($color2, 2, 2));
$colors[2] = hexdec(substr($color2, 4, 2));
$colors[3] = hexdec(substr($color1, 0, 2));
$colors[4] = hexdec(substr($color1, 2, 2));
$colors[5] = hexdec(substr($color1, 4, 2));
for($i=1; $i<strlen($str) – 1; $i++){
if($str{$i} != ‘ ‘){
$color = array();
$color[] = dechex(($colors[0] – $colors[3]) / strlen($str) * $i + $colors[3]);
$color[] = dechex(($colors[1] – $colors[4]) / strlen($str) * $i + $colors[4]);
$color[] = dechex(($colors[2] – $colors[5]) / strlen($str) * $i + $colors[5]);
$color[0] = strlen($color[0]) < 2 ? $color[0] . $color[0] : $color[0];
$color[1] = strlen($color[1]) < 2 ? $color[1] . $color[1] : $color[1];
$color[2] = strlen($color[2]) < 2 ? $color[2] . $color[2] : $color[2];
$endstr .= ‘<‘ . $html . ‘ style=”color:#’ . implode($color,”) . ‘”>’ . $str{$i} . ‘</’ . $html . ‘>’;
}else{
$endstr .= ‘ ‘;
}
}
$endstr .= ‘<‘ . $html . ‘ style=”color:#’ . $color2 . ‘;”>’ . $str{(strlen($str)-1)} . ‘</’ . $html . ‘>’;
return $endstr;
}
?>

örnek

<?php
echo gradient_text(‘red will turn into blue’, ‘#FF0000’, ‘#0000FF’);
// out puts “red will turn into blue” as a gradient from red to blue

echo gradient_text(‘red will turn into blue’, ‘f00′, ’00f’, ‘font’);
// outputs the same as above, but uses a font tag instead of span
// ( i dunno why you would do this but just in case you really want to go against good coding standards)
?>

 

Bana Ders Anlat © 2008-2022