插件40:Pound代码

<?php // Plug-in 40: Pound Code

// This is an executable example with additional code supplied
// To obtain just the plug-ins please click on the Download link

$string = <<<_END
This is a test of #comicPound Code#-<br /><br />
#2Size 2#-
#4Size 4#-
#6Size 6#-<br />
#iitalic#i-
#red#bbold red#b-#-
#uunderline#u-
#sstrikethrough#s-<br />
_END;

echo PIPHP_PoundCode($string);

function PIPHP_PoundCode($text)
{
   // Plug-in 40: Pound Code
   //
   // This plug-in recognizes and translates Pound Code
   // (also known as hash code) into its HTML equivalent.
   // Arguments required are:
   //
   //    $text:    A string containing Pound Code

   $names = array('#georgia', '#arial',   '#courier',
                  '#script',  '#impact',  '#comic',
                  '#chicago', '#verdana', '#times');
   $fonts = array('Georgia',  'Arial',    'Courier New',
                  'Script',   'Impact',   'Comic Sans MS',
                  'Chicago',  'Verdana',  'Times New Roman');
   $to    = array();
   
   for ($j = 0 ; $j < count($names) ; ++$j)
      $to[] = "<font face='$fonts[$j]'>";
      
   $text = str_ireplace($names, $to, $text);

   $text = preg_replace('/#([bius])-/i', "</$1>",
      $text);
   $text = preg_replace('/#([bius])/i',  "<$1>",
      $text);
   $text = preg_replace('/#([1-7])/',    "<font size='$1'>",
      $text);
   $text = preg_replace('/#([a-z]+)/i',  "<font color='$1'>",
      $text);
   $text = str_replace('#-', "</font>", $text);

   return $text;
}

?>

插件说明:

插件接受一个包含Pound代码的字符串,把它转化为安全的HTML代码,返回转换后的结果。他需要以下参数:

$text:需要转换的文本。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值