插件40:Pound代码
2011-10-28 11:45
127 查看
<?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:需要转换的文本。
相关文章推荐
- HBuilder的扩展插件开发暴露了一个事实:其实不能实现写一次代码实现跨平台App生成
- 深入解析js轮播插件核心代码的实现过程
- jquery dialog插件 webservice异步调用代码
- 10个超实用的APP必备插件,让你少敲80%代码,效率提速飕飕的
- 代码高亮插件SyntaxHighlighter 就是在页面中编辑代码
- My.Ioc 代码示例——使用条件绑定和元数据(可选)构建插件树
- jQuery 简单插件开发代码
- AngularJS自定义指令详解(有分页插件代码)
- Jquery省市区/县三级联动代码,以及引用area.js插件
- Sublime插件Emmet的安装及Tab补全代码
- WP常用插件程序代码分享
- 调试Angular代码的Batarang插件不能用的问题
- 突然发现这个VSPaste插件粘贴过来的代码居然有白色背景,还只有一部分有,好纠结。。。
- VS插件,好用,提高代码效率。Productivity Power Tools
- cordova热更新插件 的安装与使用 以及代码示例下载(已完结)
- 在Eclipse中使用Hibernate插件 *******生成代码
- MyEclipse安装JS代码提示(Spket插件)
- 【示例代码】基于jQuery和CSS3的图片层叠效果插件
- 让开发自动化: 用 Eclipse 插件提高代码质量
- 【mybatis源码学习】利用maven插件自动生成mybatis代码