<?
/**
** 通用表单输入类
** 处理由表单INPUT标签和TEXTAREA提交的数据
** 处理结构:允许HTML,纯TXT.
** 作者:问己
** QQ:18865382 MSN: ltianxia2006@hotmail.com
**/
class InOut {
//输入的字符串
var $strings;
//构造函数
//输入字符串,支持HTML
function inHtml($strings) {
$this->strings=$strings;
//去掉首尾空格
$this->strings=trim($this->strings);
//对特殊字符加入反斜杠字元
$this->strings=addslashes($this->strings);
//返回结果
Return $this->strings;
}
//输入字符串,纯文本字符
function inText($strings) {
$this->strings=$strings;
//去掉首尾空格
$this->strings=trim($this->strings);
//去掉HTML和PHP标记
$this->strings=strip_tags($this->strings);
//对特殊字符加入反斜杠字元
$this->strings=addslashes($this->strings);
//返回结果
Return $this->strings;
}
//输出字符串,用于TEXTAREA
function outTextarea($strings) {
$this->strings=$strings;
//去掉反斜杠字元
$this->strings=stripslashes($this->strings);
$this->strings=stripslashes($this->strings);
//返回结果
Return $this->strings;
}
//输入HTML字符串,并格式化为段落
function outHtml_format($strings) {
$this->strings=$strings;
//去掉反斜杠字元
$this->strings=stripslashes($this->strings);
$this->strings=stripslashes($this->strings);
//格式化文本
$str_array=explode("<br>",$this->strings);
$this->strings="";
while(list($key,$value)=each($str_array)) {
while(ord($value)==20){
$value=substr($value,1);
}
$this->strings.=" ".ereg_replace("(/xA1/xA1)+","",trim($value))."<br>";
}
//返回结果
Return $this->strings;
}
//输入TEXT字符串,并格式化为段落
function outText_format($strings) {
$this->strings=$strings;
//去掉反斜杠字元
$this->strings=stripslashes($this->strings);
$this->strings=stripslashes($this->strings);
//去掉HTML和PHP标记
$this->strings=strip_tags($this->strings);
//格式化文本
$str_array=explode("/n",$this->strings);
$this->strings="";
while(list($key,$value)=each($str_array)) {
while(ord($value)==20){
$value=substr($value,1);
}
$this->strings.=" ".ereg_replace("(/xA1/xA1)+","",trim($value))."<br>";
}
//返回结果
Return $this->strings;
}
//输出纯文本、并截取字符串
function outText_substr($strings,$start,$length,$hint) {
//$start开始截取位置
//$length截取长度
//截取标识,如“。。。。。”
$this->strings=$strings;
//去掉反斜杠字元
$this->strings=stripslashes($this->strings);
$this->strings=stripslashes($this->strings);
//去掉HTML和PHP标记
$this->strings=strip_tags($this->strings);
//转换特殊字符串为HTML字符
$this->strings=htmlspecialchars($this->strings);
//截取字符串
if(strlen($this->strings)>$length && $length!=0) {
for($i=0;$i<$length;$i++)
if(ord(substr($this->strings,$i,1))>0xa0) $j++;
if($j%2!=0) $length++;
$TempString=substr($this->strings,$Start,$length);
$TempString.=$hint;
return $TempString;
} else {
Return $this->strings;
}
}
}
?>
/**
** 通用表单输入类
** 处理由表单INPUT标签和TEXTAREA提交的数据
** 处理结构:允许HTML,纯TXT.
** 作者:问己
** QQ:18865382 MSN: ltianxia2006@hotmail.com
**/
class InOut {
//输入的字符串
var $strings;
//构造函数
//输入字符串,支持HTML
function inHtml($strings) {
$this->strings=$strings;
//去掉首尾空格
$this->strings=trim($this->strings);
//对特殊字符加入反斜杠字元
$this->strings=addslashes($this->strings);
//返回结果
Return $this->strings;
}
//输入字符串,纯文本字符
function inText($strings) {
$this->strings=$strings;
//去掉首尾空格
$this->strings=trim($this->strings);
//去掉HTML和PHP标记
$this->strings=strip_tags($this->strings);
//对特殊字符加入反斜杠字元
$this->strings=addslashes($this->strings);
//返回结果
Return $this->strings;
}
//输出字符串,用于TEXTAREA
function outTextarea($strings) {
$this->strings=$strings;
//去掉反斜杠字元
$this->strings=stripslashes($this->strings);
$this->strings=stripslashes($this->strings);
//返回结果
Return $this->strings;
}
//输入HTML字符串,并格式化为段落
function outHtml_format($strings) {
$this->strings=$strings;
//去掉反斜杠字元
$this->strings=stripslashes($this->strings);
$this->strings=stripslashes($this->strings);
//格式化文本
$str_array=explode("<br>",$this->strings);
$this->strings="";
while(list($key,$value)=each($str_array)) {
while(ord($value)==20){
$value=substr($value,1);
}
$this->strings.=" ".ereg_replace("(/xA1/xA1)+","",trim($value))."<br>";
}
//返回结果
Return $this->strings;
}
//输入TEXT字符串,并格式化为段落
function outText_format($strings) {
$this->strings=$strings;
//去掉反斜杠字元
$this->strings=stripslashes($this->strings);
$this->strings=stripslashes($this->strings);
//去掉HTML和PHP标记
$this->strings=strip_tags($this->strings);
//格式化文本
$str_array=explode("/n",$this->strings);
$this->strings="";
while(list($key,$value)=each($str_array)) {
while(ord($value)==20){
$value=substr($value,1);
}
$this->strings.=" ".ereg_replace("(/xA1/xA1)+","",trim($value))."<br>";
}
//返回结果
Return $this->strings;
}
//输出纯文本、并截取字符串
function outText_substr($strings,$start,$length,$hint) {
//$start开始截取位置
//$length截取长度
//截取标识,如“。。。。。”
$this->strings=$strings;
//去掉反斜杠字元
$this->strings=stripslashes($this->strings);
$this->strings=stripslashes($this->strings);
//去掉HTML和PHP标记
$this->strings=strip_tags($this->strings);
//转换特殊字符串为HTML字符
$this->strings=htmlspecialchars($this->strings);
//截取字符串
if(strlen($this->strings)>$length && $length!=0) {
for($i=0;$i<$length;$i++)
if(ord(substr($this->strings,$i,1))>0xa0) $j++;
if($j%2!=0) $length++;
$TempString=substr($this->strings,$Start,$length);
$TempString.=$hint;
return $TempString;
} else {
Return $this->strings;
}
}
}
?>