|
[PHP]
package com.ljsilver.util;
import java.util.*;
import net.acai.filter.*;
import net.acai.util.*;
public class HTMLString{
public HTMLString(){}
//从数据库取出字符串之后进行UBB转换和HTML编码然后再显示
public static String HTMLUBB(String str){
return (new MyFilter(StringUtils.replace(StringUtils.convertNewlines(StringUtils.escapeHTMLTags(str)), " ", " "))).getFilterString();
}
//从数据库取出字符串之后进行html编码然后再显示
public static String HTMLEntitle(String str){
fString = repstr(fString, "&","&",
fString = repstr(fString, "´","'");
fString = repstr(fString, ""","\"");
fString = repstr(fString, "<","<");
fString = repstr(fString, ">",">");
fString = repstr(fString, " "," ");
fString = repstr(fString, "<br>","\n");
return (fString);
}
//从页面的textarea取字符串时将各种系统的换行符都转换成'\n'
public static HTMLBR(String str){
fString = repstr(fString, "\n ","\r\n");
fString = repstr(fString, "\n ","\r");
}
//判断是否合法的用户名字符串
public static boolean isUserNameString(String str){
if(str!=null&&str.length()>=6&&str.length()<=20&&str.matches("[0-9a-zA-Z[-_.]]")){
return true;
}else{
return false;
}
}
//判断是否合法的密码字符串
public static boolean isPassWordString(String str){
if(str!=null&&str.length()>=6&&str.length()<=20){
return true;
}else{
return false;
}
}
//字符串替换
public static String repstr(String str, String strDen, String strSrc){
int iLen = str.length();
int iDenLen = strDen.length();
int iSrcLen = strSrc.length();
String strReturn = "";
int iSearchedFrom = 0 ;
int iPrevSearchedFrom = 0;
while ( (iSearchedFrom = str.indexOf(strSrc , iSearchedFrom)) != -1 ){
strReturn += str.substring(iPrevSearchedFrom, iSearchedFrom);
strReturn += strDen;
iSearchedFrom += iSrcLen;
iPrevSearchedFrom = iSearchedFrom;
}
if ( iPrevSearchedFrom !=0 )
strReturn += str.substring( str.lastIndexOf(strSrc) + iSrcLen , str.length());
else
strReturn = str;
return(strReturn);
}
}
[/PHP] |
|