|  | 
PHP gradient text yazı yazmak  - PHP Webmaster bilgi bankası, knowledge base Webmaster Araçları| AnaSayfa > PHP  > PHP gradient text yazı yazmak |  |  |  | Kategori | : PHP |  | Gönderen | : Admin |  | Tarih | : 2009-05-29 |  | Puan | : 0  | Katılımcı : 0 |  | Okunma | : 5418 |  |  |  |  |  |  |  |  | <?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)
 ?>
 
 
 | 
 | Yorumlar |  | Henüz Kimse Yorum Yapmamış, ilk yorumu siz ekleyin! |  | Yorum Ekleme Aparatı |  | Yorum Eklemek için lütfen sol menuden giris yapınız.. |  | Toplam 0 yorum listelendi. | 
 |