选择显示字体大小

ubbcode类


<?
//ubbcode类
class ubbcode{
var &#36;call_time=0;
//可处理标签及处理函数对应表
var &#36;tags = array( //小写的标签 => 对应的处理函数
'url' => '&#36;this->url',
'email' => '&#36;this->email',
'img' => '&#36;this->img',
'flash' => '&#36;this->flash',
'sound' => '&#36;this->sound',

'black' => '&#36;this->font_color',
'white' => '&#36;this->font_color',
'red' => '&#36;this->font_color',
'pink' => '&#36;this->font_color',
'blue' => '&#36;this->font_color',
'green' => '&#36;this->font_color',
'olive' => '&#36;this->font_color',
'navy' => '&#36;this->font_color',
'gray'=> '&#36;this->font_color',
'fuchsia' => '&#36;this->font_color',
'yellow' => '&#36;this->font_color',
'silver' => '&#36;this->font_color',
'purple' => '&#36;this->font_color',

'marquee' => '&#36;this->simple',
'b' => '&#36;this->simple',
'i' => '&#36;this->simple',
'u' => '&#36;this->simple',
'tt' => '&#36;this->simple',
's' => '&#36;this->simple',
'strike' => '&#36;this->simple',
'h1' => '&#36;this->simple',
'h2' => '&#36;this->simple',
'h3' => '&#36;this->simple',
'h4' => '&#36;this->simple',
'h5' => '&#36;this->simple',
'h6' => '&#36;this->simple',
'sup' => '&#36;this->simple',
'sub' => '&#36;this->simple',
'em' => '&#36;this->simple',
'strong' => '&#36;this->simple',
'code' => '&#36;this->simple',
'samp' => '&#36;this->simple',
'kbd' => '&#36;this->simple',
'var' => '&#36;this->simple',
'dfn' => '&#36;this->simple',
'cite' => '&#36;this->simple',
'small' => '&#36;this->simple',
'big' => '&#36;this->simple',
'blink' => '&#36;this->simple'
);
//url裢接属性
var &#36;attr_url;
//url合法性检查对象
var &#36;urlcheck;
 
function ubbcode(&#36;attr_url){
&#36;this->attr_url = ''.&#36;attr_url;
&#36;this->urlcheck = new urlcheck();
}
 
//对&#36;str进行ubb编码解析
function parse(&#36;str){
&#36;this->call_time++;
&#36;parse = ''.htmlencode(&#36;str);
 
&#36;ret = '';
while(true){
&#36;eregi_ret=eregi(&quot;\[[#]{0,1}[[:alnum:]]{1,7}\]&quot;,&#36;parse,&#36;eregi_arr); //查找[xx]
if(!&#36;eregi_ret){
&#36;ret .= &#36;parse;
break; //如果没有,返回
}
&#36;pos = @strpos(&#36;parse,&#36;eregi_arr[0]);
&#36;tag_len=strlen(&#36;eregi_arr[0])-2;//标记长度
&#36;tag_start=substr(&#36;eregi_arr[0],1,&#36;tag_len);
&#36;tag=strtolower(&#36;tag_start);
 
if(((&#36;tag==&quot;url&quot;) or (&#36;tag==&quot;email&quot;) or (&#36;tag==&quot;img&quot;) or (&#36;tag==&quot;flash&quot;)) and (&#36;this->call_time>1)){
echo &#36;this->call_time.&quot;<br>&quot;;
return &#36;parse;//如果不能是不能嵌套的标记,直接返回
}
 
&#36;parse2 = substr(&#36;parse,0,&#36;pos);//标记之前
&#36;parse = substr(&#36;parse,&#36;pos+&#36;tag_len+2);//标记之后
if(!isset(&#36;this->tags[&#36;tag])){
echo &quot;&#36;tag_start<br>&quot;;
&#36;ret .= &#36;parse2.'['.&#36;tag_start.']';
continue;//如果是不支持的标记
}
 
//查找对对应的结束标记
&#36;eregi_ret=eregi(&quot;\[\/&quot;.&#36;tag.&quot;\]&quot;,&#36;parse,&#36;eregi_arr);
if(!&#36;eregi_ret){
&#36;ret .= &#36;parse2.'['.&#36;tag_start.']';
continue;//如果没有对应该的结束标记
}
&#36;pos=strpos(&#36;parse,&#36;eregi_arr[0]);
&#36;value=substr(&#36;parse,0,&#36;pos);//这是起止标记之间的内容
&#36;tag_end=substr(&#36;parse,&#36;pos+2,&#36;tag_len);
&#36;parse=substr(&#36;parse,&#36;pos+&#36;tag_len+3);//结束标记之后的内容
 
if((&#36;tag!=&quot;url&quot;) and (&#36;tag!=&quot;email&quot;) and (&#36;tag!=&quot;img&quot;)and (&#36;tag!=&quot;flash&quot;)){
&#36;value=&#36;this->parse(&#36;value);
}
 
&#36;ret .= &#36;parse2;
eval('&#36;ret .= '.&#36;this->tags[&#36;tag].'(&quot;'.&#36;tag_start.'&quot;,&quot;'.&#36;tag_end.'&quot;,&quot;'.&#36;value.'&quot;);');
}
&#36;this->call_time--;
return &#36;ret;
}
 
function simple(&#36;start,&#36;end,&#36;value){
return '<'.&#36;start.'>'.&#36;value.'</'.&#36;end.'>';
}
 
function url(&#36;start,&#36;end,&#36;value){
&#36;trim_value=trim(&#36;value);
if (strtolower(substr(&#36;trim_value,0,7))!=&quot;http://&quot;)
&#36;trim_value=&quot;http://&quot;.&#36;trim_value;
if(&#36;this->urlcheck->check(&#36;trim_value)) return '<a href=&quot;'.&#36;trim_value.'&quot; '.&#36;this->attr_url.'>'.&#36;value.'</a>';
else return '['.&#36;start.']'.&#36;value.'[/'.&#36;end.']';
}
 
function email(&#36;start,&#36;end,&#36;value){
if(emailcheck(&#36;value)) return '<a href=&quot;mailto:'.&#36;value.'&quot;>'.&#36;value.'</a>';
else return '['.&#36;start.']'.&#36;value.'[/'.&#36;end.']';
}
 
function img(&#36;start,&#36;end,&#36;value){
&#36;trim_value=trim(&#36;value);
if ((strtolower(substr(&#36;trim_value,0,7))!=&quot;http://&quot;) or (&#36;this->urlcheck->check(&#36;trim_value)))
return '<img src=&quot;'.&#36;trim_value.'&quot;></img>';
else return '['.&#36;start.']'.&#36;value.'[/'.&#36;end.']';
}

function flash(&#36;start,&#36;end,&#36;value){
&#36;trim_value=trim(&#36;value);
if ((strtolower(substr(&#36;trim_value,0,7))!=&quot;http://&quot;) or (&#36;this->urlcheck->check(&#36;trim_value)))

return '<embed src='.&#36;trim_value.' quality=high pluginspage=http://www.macromedia.com/shockwave/download/index.cgi?p1_prod_version=shockwaveflash type=application/x-shockwave-flash width=520 height=360>';

else return '['.&#36;start.']'.&#36;value.'[/'.&#36;end.']';
}

function sound(&#36;start,&#36;end,&#36;value){
&#36;trim_value=trim(&#36;value);
if ((strtolower(substr(&#36;trim_value,0,7))!=&quot;http://&quot;) or (&#36;this->urlcheck->check(&#36;trim_value)))

return &quot;<embed src=&quot;.&#36;trim_value.&quot; hidden autostart=true loop=true>&quot;;

else return '['.&#36;start.']'.&#36;value.'[/'.&#36;end.']';
}

function font_color(&#36;start,&#36;end,&#36;value){
if(strstr(&quot;blackwhiteredpinkbluegreenolivenavygrayfuchsiayellowsilverpurple&quot;,&#36;start))
return &quot;<font color=&quot;.&#36;start.&quot;>&quot;.&#36;value.&quot;</font>&quot;;
else return '['.&#36;start.']'.&#36;value.'[/'.&#36;end.']';
}
}
 
//urlcheck.php
class urlcheck{
var &#36;regex = array(//协议名(注意在这里必须写成小写) => 对应的正则表达式
'ftp' => '&#36;this->ftpurl',
'file' => '&#36;this->fileurl',
'http' => '&#36;this->httpurl',
'https' => '&#36;this->httpurl',
'gopher' => '&#36;this->gopherurl',
'news' => '&#36;this->newsurl',
'nntp' => '&#36;this->nntpurl',
'te.net' => '&#36;this->te.neturl',
'wais' => '&#36;this->waisurl'
);
 
var &#36;lowalpha;
var &#36;hialpha;
var &#36;alpha;
var &#36;digit;
var &#36;safe;
var &#36;extra;
var &#36;national;
var &#36;punctuation;
var &#36;reserved;
var &#36;hex;
var &#36;escape;
var &#36;unreserved;
var &#36;uchar;
var &#36;xchar;
var &#36;digits;
 
var &#36;urlpath;
var &#36;password;
var &#36;user;
var &#36;port;
var &#36;hostnumber;
var &#36;alphadigit;
var &#36;toplabel;
var &#36;domainlabel;
var &#36;hostname;
var &#36;host;
var &#36;hostport;
var &#36;login;
 
//ftp
var &#36;ftptype;
var &#36;fsegment;
var &#36;fpath;
var &#36;ftpurl;
 
//file
var &#36;fileurl;
 
//http,https
var &#36;search;
var &#36;hsegment;
var &#36;hpath;
var &#36;httpurl;
 
//gopher
var &#36;gopher_string;
var &#36;selector;
var &#36;gtype;
var &#36;gopherurl;
 
//news
var &#36;article;
var &#36;group;
var &#36;grouppart;
var &#36;newsurl;
 
//nntp
var &#36;nntpurl;
 
//te.net
var &#36;te.neturl;
 
//wais
var &#36;wpath;
var &#36;wtype;
var &#36;database;
var &#36;waisdoc;
var &#36;waisindex;
var &#36;waisdatabase;
var &#36;waisurl;
 
function check(&#36;url){
&#36;pos = @strpos(&#36;url,':',1);
if(&#36;pos<1) return false;
&#36;prot = substr(&#36;url,0,&#36;pos);
if(!isset(&#36;this->regex[&#36;prot])) return false;
eval('&#36;regex = '.&#36;this->regex[&#36;prot].';');
return ereg('^'.&#36;regex.'&#36;',&#36;url);
}
 
function urlcheck(){
&#36;this->lowalpha = '[a-z]';
&#36;this->hialpha = '[a-z]';
&#36;this->alpha = '('.&#36;this->lowalpha.''.&#36;this->hialpha.')';
&#36;this->digit = '[0-9]';
&#36;this->safe = '[&#36;.+_-]';
&#36;this->extra = '[*()\'!,]';
&#36;this->national = '([{}\^~`]\\[\\])';
&#36;this->punctuation = '[<>#%&quot;]';
&#36;this->reserved = '[?;/:@&=]';
&#36;this->hex = '('.&#36;this->digit.'[a-fa-f])';
&#36;this->escape = '(%'.&#36;this->hex.'{2})';
&#36;this->unreserved = '('.&#36;this->alpha.''.&#36;this->digit.''.&#36;this->safe.''.&#36;this->extra.')';
&#36;this->uchar = '('.&#36;this->unreserved.''.&#36;this->escape.')';
&#36;this->xchar = '('.&#36;this->unreserved.''.&#36;this->reserved.''.&#36;this->escape.')';
&#36;this->digits = '('.&#36;this->digit.'+)';
 
&#36;this->urlpath = '('.&#36;this->xchar.'*)';
&#36;this->password = '(('.&#36;this->uchar.'[?;&=]'.')*)';
&#36;this->user = '(('.&#36;this->uchar.'[?;&=]'.')*)';
&#36;this->port = &#36;this->digits;
&#36;this->hostnumber = '('.&#36;this->digits.'.'.&#36;this->digits.'.'.&#36;this->digits.'.'.&#36;this->digits.')';
&#36;this->alphadigit = '('.&#36;this->alpha.''.&#36;this->digit.')';
&#36;this->toplabel = '('.&#36;this->alpha.'('.&#36;this->alpha.'('.&#36;this->alphadigit.'-)*'.&#36;this->alphadigit.'))';
&#36;this->domainlabel = '('.&#36;this->alphadigit.'('.&#36;this->alphadigit.'('.&#36;this->alphadigit.'-)*'.&#36;this->alphadigit.'))';
&#36;this->hostname = '(('.&#36;this->domainlabel.'\\.)*'.&#36;this->toplabel.')';
&#36;this->host = '('.&#36;this->hostname.''.&#36;this->hostnumber.')';
&#36;this->hostport = '('.&#36;this->host.'(:'.&#36;this->port.')?)';
&#36;this->login = '(('.&#36;this->user.'(:'.&#36;this->password.')?@)?'.&#36;this->hostport.')';
 
&#36;this->ftptype = '[aidaid]';
&#36;this->fsegment = '(('.&#36;this->uchar.'[?:@&=])*)';
&#36;this->fpath = '('.&#36;this->fsegment.'(/'.&#36;this->fsegment.')*)';
&#36;this->ftpurl = '([ff][tt][pp]://'.&#36;this->login.'(/'.&#36;this->fpath.'(;[tt][yy][pp][ee]='.&#36;this->ftptype.')?)?)';
 
&#36;this->fileurl = '([ff][ii][ll][ee]://('.&#36;this->host.'[ll][oo][cc][aa][ll][hh][oo][ss][tt])?/'.&#36;this->fpath.')';
 
&#36;this->search = '(('.&#36;this->uchar.'[;:@&=])*)';
&#36;this->hsegment = '(('.&#36;this->uchar.'[;:@&=])*)';
&#36;this->hpath = '('.&#36;this->hsegment.'(/'.&#36;this->hsegment.')*)';
&#36;this->httpurl = '([hh][tt][tt][pp][ss]?://'.&#36;this->hostport.'(/'.&#36;this->hpath.'([?]'.&#36;this->search.')?)?)';
 
&#36;this->gopher_string = '('.&#36;this->xchar.'*)';
&#36;this->selector = '('.&#36;this->xchar.'*)';
&#36;this->gtype = &#36;this->xchar;
&#36;this->gopherurl = '([gg][oo][pp][hh][ee][rr]://'.&#36;this->hostport.'(/('.&#36;this->gtype.'('.&#36;this->selector.'(%09'.&#36;this->search.'(%09'.&#36;this->gopher_string.')?)?)?)?)?)';
 
&#36;this->article = '(('.&#36;this->uchar.'[;/?:&=])+@'.&#36;this->host.')';
&#36;this->group = '('.&#36;this->alpha.'('.&#36;this->alpha.''.&#36;this->digit.'[-.+_])*)';
&#36;this->grouppart = '([*]'.&#36;this->group.''.&#36;this->article.')';
&#36;this->newsurl = '([nn][ee][ww][ss]:'.&#36;this->grouppart.')';
 
&#36;this->nntpurl = '([nn][nn][tt][pp]://'.&#36;this->hostport.'/'.&#36;this->group.'(/'.&#36;this->digits.')?)';
 
&#36;this->te.neturl = '([tt][ee][ll][nn][ee][tt]://'.&#36;this->login.'/?)';
 
&#36;this->wpath = '('.&#36;this->uchar.'*)';
&#36;this->wtype = '('.&#36;this->uchar.'*)';
&#36;this->database = '('.&#36;this->uchar.'*)';
&#36;this->waisdoc = '([ww][aa][ii][ss]://'.&#36;this->hostport.'/'.&#36;this->database.'/'.&#36;this->wtype.'/'.&#36;this->wpath.')';
&#36;this->waisindex = '([ww][aa][ii][ss]://'.&#36;this->hostport.'/'.&#36;this->database.'[?]'.&#36;this->search.')';
&#36;this->waisdatabase = '([ww][aa][ii][ss]://'.&#36;this->hostport.'/'.&#36;this->database.')';
&#36;this->waisurl = '('.&#36;this->waisdatabase.''.&#36;this->waisindex.''.&#36;this->waisdoc.')';
}
}
 

function htmlencode(&#36;str){
&#36;str = (string)&#36;str;
 
&#36;ret = '';
&#36;len = strlen(&#36;str);
&#36;nl = false;
for(&#36;i=0;&#36;i<&#36;len;&#36;i++){
&#36;chr = &#36;str[&#36;i];
switch(&#36;chr){
case '<':
&#36;ret .= '<';
&#36;nl = false;
break;
case '>':
&#36;ret .= '>';
&#36;nl = false;
break;
case '&quot;':
&#36;ret .= '&quot;';
&#36;nl = false;
break;
case '&':
&#36;ret .= '&';
&#36;nl = false;
break;
/*
case ' ':
&#36;ret .= ' ';
&#36;nl = false;
break;
*/
case chr(9):
&#36;ret .= ' ';
&#36;nl = false;
break;
/*
case chr(10):
if(&#36;nl) &#36;nl = false;
else{
&#36;ret .= '<br>';
&#36;nl = true;
}
break;

case chr(13):
if(&#36;nl) &#36;nl = false;
else{
&#36;ret .= '<br>';
&#36;nl = true;
}
break;
*/
default:
&#36;ret .= &#36;chr;
&#36;nl = false;
break;
}
}
 
return &#36;ret;
}
 
 
function htmlencode4textarea(&#36;str){
&#36;str = (string)&#36;str;
 
&#36;ret = '';
&#36;len = strlen(&#36;str);
for(&#36;i=0;&#36;i<&#36;len;&#36;i++){
&#36;chr = &#36;str[&#36;i];
switch(&#36;chr){
case '<':
&#36;ret .= '<';
break;
case '>':
&#36;ret .= '>';
break;
case '&quot;':
&#36;ret .= '&quot;';
break;
case '&':
&#36;ret .= '&';
break;
case ' ':
&#36;ret .= ' ';
break;
case chr(9):
&#36;ret .= ' ';
break;
default:
&#36;ret .= &#36;chr;
break;
}
}
 
return &#36;ret;
}
 
function emailcheck(&#36;email){
&#36;ret=false;
if(strstr(&#36;email, '@') && strstr(&#36;email, '.')){
if(eregi(&quot;^([_a-z0-9]+([\\._a-z0-9-]+)*)@([a-z0-9]{2,}(\\.[a-z0-9-]{2,})*\\.[a-z]{2,3})&#36;&quot;, &#36;email)){
&#36;ret=true;
}
}
return &#36;ret;
}
 
function str2url(&#36;path){
return eregi_replace(&quot;%2f&quot;,&quot;/&quot;,urlencode(&#36;path));
}

?>
--------------------------

说明:在网上找了半天发现全是何志强的那段代码,我也就拿来改了一下用上了。其中加入了一部分自己的内容,只是还不太清楚如何规定图片等元素的大小。我曾经把 function img(&#36;start,&#36;end,&#36;value){
&#36;trim_value=trim(&#36;value);
if ((strtolower(substr(&#36;trim_value,0,7))!=&quot;http://&quot;) or (&#36;this->urlcheck->check(&#36;trim_value)))
return '<img src=&quot;'.&#36;trim_value.'&quot;></img>';
else return '['.&#36;start.']'.&#36;value.'[/'.&#36;end.']';
}
改为:
function img(&#36;start,&#36;end,&#36;value){
&#36;trim_value=trim(&#36;value);
if ((strtolower(substr(&#36;trim_value,0,7))!=&quot;http://&quot;) or (&#36;this->urlcheck->check(&#36;trim_value)))
{
&#36;pisces=explode(&quot; &quot;,&#36;start);
if(!is_int(&#36;pisces[1]) !!is_int(&#36;pisces[2]))
return '<img src=&quot;'.&#36;trim_value.'&quot; width=&#36;pisces[1] height=&#36;pisces[2]></img>';
else
return '<img src=&quot;'.&#36;trim_value.'&quot;></img>';
}

else return '['.&#36;start.']'.&#36;value.'[/'.&#36;end.']';
}

但由于对前面的正则表达式不熟悉没成功。

  


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons