UBB标签转html代码的PHP函数

添加时间:12-11-06 所属分类:PHP工具与代码
  转载自http://www.21andy.com/blog/20060915/427.html

[code]<?php
function format_output($output) {
/****************************************************************************
* Takes a raw string ($output) and formats it for output using a special
* stripped down markup that is similar to HTML
****************************************************************************/

$output = htmlspecialchars(stripslashes($output));
$output = ereg_replace(' ', '&nbsp;&nbsp;', $output);
/* new paragraph */
$output = str_replace('[p]', '<p>', $output);

/* bold */
$output = str_replace('[b]', '<b>', $output);
$output = str_replace('[/b]', '</b>', $output);

/* italics */
$output = str_replace('[i]', '<i>', $output);
$output = str_replace('[/i]', '</i>', $output);

/* preformatted */
$output = str_replace('[pre]', '<pre>', $output);
$output = str_replace('[/pre]', '</pre>', $output);

$output = str_replace('[u]', '<u>', $output);
$output = str_replace('[/u]', '</u>', $output);

/* indented blocks (blockquote) */
$output = str_replace('[indent]', '<blockquote>', $output);
$output = str_replace('[/indent]', '</blockquote>', $output);

/* anchors */
$output = ereg_replace('[anchor=&quot;([[:graph:]]+)&quot;]', '<a name="1"></a>', $output);

/* links, note we try to prevent javascript in links */
$output = str_replace('[link=&quot;javascript', '[link=&quot; javascript', $output);
$output = ereg_replace('[link=&quot;([[:graph:]]+)&quot;]', '<a href="1">', $output);
$output = str_replace('[/link]', '</a>', $output);

$output = ereg_replace('[img=&quot;([[:graph:]]+)&quot;]', '<div align="center"><img src="1">', $output);
$output = str_replace('[/img]', '</img></div>', $output);



return nl2br($output);
}
?>[/code]

前篇:PHP实现HTML代码转UBB标签 后篇:php完全过滤HTML,JS,CSS等标签
发表我的评论


推荐文章   被宠坏的中国式子女   35岁之后当妈妈——是什么让她们毅然决...   日本小学的开学第一课,竟然讲这些!我...   为让妹妹上学 95后重庆小伙去新疆阿拉尔...   执着守望梦想 首演灌酒壮胆 济南街头艺...
随机文章   再谈PHP开发者常犯的10个MySQL错误   PHP开发者常犯的10个MySQL错误   自后向前面消除3个汉字   用cPanel向虚拟主机导入大型数据库   用正则表达式判断,验证是否含有中文字...
广告

其他推荐

因为本站所有内容均转载自其它媒体,本意为公众提供免费服务,但并不代表本网赞同其观点,也不能对其真实性验证负责,如稿件版权单位或个人不想在本网发布,请与我联系,本人会立即将其撤除,谢谢.联系方式:atseashawk@163.com QQ:99289555