Anasayfa > Hazır Kodlar > PHP > Kod renklendirme
Hazırlanıyor..
Makaleye verilen puanlar Makaleye verilen puanlar

Kod renklendirme



 

forumlardaki gibi [php][/php] içine alinan kodlarin renklendirilmesi

<?
function bbencode_highlight_php($text) {
     
     $matches = array();
     $match_count = preg_match_all("#\[php\](.*?)\[/php\]#si", $text, $matches);
     
     for ($i = 0; $i < $match_count; $i++)
     {
          $before_replace = $matches[1][$i];
          $after_replace = trim($matches[1][$i]);
          $str_to_match = "[php]" . $before_replace . "[/php]";
          $replacement = "";
          $after_replace = str_replace('<', '<', $after_replace);
          $after_replace = str_replace('>', '>', $after_replace);
          $after_replace = str_replace('&', '&', $after_replace);
          $added = FALSE;
          if (preg_match('/^<\?.*?\?>$/si', $after_replace) <= 0) {
               $after_replace = "<?php $after_replace ?>";
               $added = TRUE;
          }
          if(strcmp('4.2.0', phpversion()) > 0) {
               ob_start();
               highlight_string($after_replace);
               $after_replace = ob_get_contents();
               ob_end_clean();
          }
          else {
               $after_replace = highlight_string($after_replace, TRUE);
          }
          if ($added == TRUE) {
               $after_replace = str_replace('<font color="#0000BB"><?php <br>', '<font color="#0000BB">', $after_replace);
               $after_replace = str_replace('<font color="#0000BB"><br>?></font>', '', $after_replace);
          }
          $after_replace = preg_replace('/<font color="(.*?)">/si', '<span style="color: \\1;">', $after_replace);
          $after_replace = str_replace('</font>', '</span>', $after_replace);
          $after_replace = str_replace("", '', $after_replace);
          $replacement .= $after_replace;
          
          $text = str_replace($str_to_match, $replacement, $text);
     }
     
     return $text;
}
?>



Bu makalenin yazar yada kaynağını bildirmek için tıklayınız.

Digg this Post! Add Post to del.icio.us Bookmark Post in Technorati Furl this Post!
Eklenme tarihi: 12-8-2006

Bu Makaleye Verilen Puan:    Makaleye verilen puanlar Makaleye verilen puanlar
Bu Makaleye Puan Ver  

Bölüm Başlık Kullanıcı Yorumları


Bu makaleye yorum gönderilmemiş, ilk yorumu sen gönder !

Yorum Ekle  

Bölüm Başlık İlgili Dökümanlar

Reklam Netinternet
Gizlilik | Copyright © 2006-2009 ™ Tüm hakları saklıdır.
Powered by BilgiPortal v2.2
Frasb Etiler WebTasarım Web Tasarım