[code]
/**替换单引号,用于sql语句*/
function formatStr($str){
$pos = strpos($str,"\'");
if($pos===false){
$str = str_replace("'","\'",$str);
}else{
$str = str_replace("\'","'",$str);
$str = str_replace("'","\'",$str);
}
return trim($str);
}
/**替换单引号和双引号,用于文本框显示*/
function formatDisplay($str){
$str = str_replace("'","'",$str);
$str = str_replace('"',""",$str);
return trim($str);
}
/**替换双引号,用于生成CSV文件*/
function formatCSVStr($str){
$str = str_replace("\"","\"\"",$str);
return trim($str);
}
/**将日期格式化为mysql的默认格式*/
function to_mysql_date($dt){
$result = $format;
if (ereg ("([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})", $dt, $adat))
return $adat[3]."-".$adat[1]."-".$adat[2];
if ($dt=="N/A")
return "0000-00-00";
else
return "3333-03-03";
}
/**将mysql的默认日期格式转为指定日期格式*/
function from_mysql_date($mysql_dt,$format ="%m/%d/%Y"){
$result = $format;
if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $mysql_dt, $adat))
if (intval($adat[1])==0 && intval($adat[2])==0 && intval($adat[3])==0){
return "N/A";
}
else if (intval($adat[1])==3333 && intval($adat[2])==3 && intval($adat[3])==3){
return "Ongoing Offer";
}
else{
return (ereg_replace("%Y",$adat[1],ereg_replace("%d",$adat[3],ereg_replace("%m",$adat[2],$result))));
}
else
return "Expiration Unknown";
}
[/code]