// 获取时间
echo date("Y-m-d H:i:s") . "<br />";
# 2019-07-05 09:56:53

// 读取服务器端文件输出
$file = fopen("hello.txt", "r");

// 按行读取
while (!feof($file)) {
    echo fgets($file) . "<br />";

// 关闭文件

// 设置cookie
setcookie("name", "Tom");

C 常用功能函数 整理


[code=C/C++]rn/*rn TSDK.Hrnrn Definitions for Common functions and string functions.rnrn Copyright (c) Tody 2010rn All Rights Reserved rn*/rnrn#ifndef __TSDK_H__rn#define __TSDK_H__rnrn#include rn#include rn#include rnrn#if __STDC__rn# define _Cdeclrn#elsern# define _Cdecl cdeclrn#endifrnrn#ifdef DOSrn# define SAY(x...) printf(x)rn#elsern# define SAY(x) printf(x)rn#endifrnrn#ifndef MAXrn# define MAX(a, b) ((a) < (b) ? (b) : (a))rn#endifrn#ifndef MINrn# define MIN(a, b) ((a) < (b) ? (a) : (b))rn#endifrnrn#define FATAL(x) do \rn printf("\n[-] PROGRAM ABORT : %s", x); \rn exit(1); \rn while (0)rnrn#define VERSION "1.0.0"rnrn#define true 1rn#define false 0rnrntypedef char bool;rnrnrn/* Function Declare */rnbool _Cdecl copy_file (char *scr_file, char *dst_file, int flag);rnbool _Cdecl file_exist (char *file);rnrnchar *_Cdecl skip_spaces (const char *str);rnchar *_Cdecl strim (char *p);rnint _Cdecl t_random (int a, int b);rnbool _Cdecl log_save (char *log_file, char *ErrMsg);rnrnbool _Cdecl is_leap_yaer(int year);rnint _Cdecl which_day (int year, int mon, int day);rnrnbool _Cdecl is_little_endian( void );rnrn/*******************************************************************rn* Remove leading whitespace string rn*******************************************************************/rnchar *skip_spaces(const char *str)rnrn while (isspace(*str))rn ++str;rn return (char *)str;rnrnrn/*******************************************************************rn* Remove Left and right blank of string rn*******************************************************************/rnchar *strim(char *s)rnrn size_t size;rn char *end;rnrn s = skip_spaces(s);rn size = strlen(s);rn if (!size)rn return s;rnrn end = s + size - 1;rn while (end >= s && isspace(*end))rn end--;rn *(end + 1) = '\0';rnrn return s;rnrnrn/*******************************************************************rn* Random a number between a and b (not contain b)rn*******************************************************************/rnint t_random (int a, int b)rnrn if (a >= b) return -1;rn srand(time(NULL)); /* Seed is time */rn return (rand()%(b-a) + a); rnrnrn/*******************************************************************rn* Copy file from scr_file to des_filern*******************************************************************/rnbool copy_file (char *scr_file, char *des_file, int flag)rnrn FILE *fin,*fout;rn char ch;rn rn if (0 == flag && file_exist(des_file) == 1) return false; rn rn if ((fin=fopen(scr_file, "rb")) == NULL)rn rn return false;rn rn if ((fout=fopen(des_file, "wb")) == NULL)rn rn return false;rn rnrn ch = fgetc(fin); /* File copying... */rn while ( ch != EOF)rn rn fputc(ch, fout);rn ch = fgetc(fin); rn rnrn fclose(fout);rn fclose(fin);rn return true;rnrnrn/*******************************************************************rn* Check file is exist or notrn*******************************************************************/rnbool file_exist (char *file)rnrn return !access(file,0); /* File exist, access() return 0, else return -1 */rnrnrn/*******************************************************************rn* Save Log to Filern*******************************************************************/rnbool log_save ( char *log_file, char *ErrMsg)rnrn FILE *p;rn p = fopen(log_file, "wb");rn if ( p == NULL ) return false;rn fprintf(p, "[Err]: %s\n", ErrMsg); /* Write ErrMsg to File. */rn fclose(p);rn return true;rnrnrn/*******************************************************************rn* Is Leap Yearrn*******************************************************************/rnrnbool is_leap_year ( int year )rnrn return ( ((year%100==0) && (year%400==0)) || ((year%100!=0) && (year%4==0)) );rnrnrn/*******************************************************************rn* Which Day with Year+Mon+day Specifiedrn*******************************************************************/rnint which_day (int year, int mon, int day)rnrn static int mdays[] = 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30 ;rn int i, days = day;rn rn for (i=0; i2)rn rn if ( is_leap_year(year) ) ++days;rn rn return days;rnrnrn/*******************************************************************rn* Check CPU endian typern*******************************************************************/rnbool is_little_endian( void )rnrn union wrn int a;rn char b;rn c;rnrn c.a = 1;rnrn return ( c.b == 1 );rnrn#endif /* __tsdk_h__ */rnrn[/code] 论坛