rss· 投稿· 设为首页· 加入收藏· 繁體版
当前位置: 火魔网 » 程序开发 » PHP

PHP中常用的函数

<?
class useful{
function formatnumber(num){
return number_format(num, 2, ".", ","); function formatstring(string = ""){
string = preg_replace(array("/ /", "/ /"), array("&nbsp;", "&nbsp;&nbsp;"), string);
return nl2br(string); function formatcontent(text){
trans = get_html_translation_table(HTML_SPECIALCHARS);
trans = array_flip(trans);
text = strtr(text, trans);
//text = str_replace("\n", "<br>", text);
//text = str_replace(" ", "&nbsp;", text);
return text; function bitsize(num){
if(!preg_match("/^[0-9]+/", num)) return 0;
return num > 1024 ? (num/1024 > 1024 ? round(num/1024/1024, 2)." Mb" : round(num/1024, 2)." Kb") : num." 字节"; function add_s(&array){
foreach(array as key=>value){
if(!is_array(value)){
array[key]=addslashes(value);
}else{
this->add_s(array[key]); } function specialhtml(&array){
if(is_array(array)){//数组处理
foreach(array as key=>value){
if(!is_array(value)){
array[key]=htmlspecialchars(value);
}else{
this->specialhtml(array[key]); }
}else{
array = htmlspecialchars(array); }
function msubstr(str, start, len) {
tmpstr = "";
strlen = start + len;
for(i = 0; i < strlen; i++) {
if(ord(substr(str, i, 1)) > 0xa0) {
tmpstr .= substr(str, i, 2);
i++;
} else
tmpstr .= substr(str, i, 1); return tmpstr; function alert_msg(msg, direct = "0"){
switch(direct){
case '0'://提示
script = "";
case '1'://提示刷新返回
script = "location.href=\""._SESSION["HTTP_REFERER"]."\";";
break;
case '2'://提示返回
script = "history.back();";
break;
default://提示转向指定页面
script = "location.href=\"".direct."\";"; echo "<script language='javascript'>window.alert('".msg."');".script."</script>";
exit; function aweek(gdate = "", first = 0){
if(!gdate) gdate = date("Y-m-d");
w = date("w", strtotime(gdate));//取得一周的第几天,星期天开始0-6
dn = w ? w - first : 6;//要减去的天数
st = date("Y-m-d", strtotime("gdate -".dn." days"));
en = date("Y-m-d", strtotime("st +6 days"));
return array(st, en);//返回开始和结束日期 function checkurl(){ //echo "referer:"._SESSION['HTTP_REFERER'];
if(!isset(_SESSION['HTTP_REFERER'])) {
header("location: index.php");
exit; urlar = parse_url(_SESSION['HTTP_REFERER']); if(_SERVER["HTTP_HOST"] != urlar["host"]) {
header("location: index.php");
exit; }
function readfiles(file){
tdata = "";
fp = fopen(file, "r"); if(filesize(file) <= 0) return; while(data = fread(fp, filesize(file))){
tdata .= data; fclose(fp);
return tdata; }
?>
顶一下
(0)
踩一下
(0)