使用PHP的strtotime计算两个给定日期之间的天数PHP的strtotime函数用于将任何英文文本的日期时间描述解析为Unix时间戳。这个函数将使用TZ环境变量(如果有的话)来计算时间戳。如果执行成功它返回一个时间戳,否则返回FALSE。在PHP 5.1.0之前,这个函数将返回-1。$date1 = date(‘Y-m-d’);$date2 =……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1750浏览 1849个赞
mysql_num_fields用于获得查询结果的列数,如果执行成功返回列数,执行失败,返回boolean值<?php$UserName = 'abc';$Password = '1234';$DbHandle = mysql_connect ('localhost', $UserN……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3159浏览 2222个赞
mysql_fetch_row用于从mysql数据库中查询数据,并保存到list中 语法如下:array mysql_fetch_row (resource $Result_Set) 如果执行成功,则返回l……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2221浏览 2427个赞
mysql_fetch_object函数用于,提取结果行从一个MySQL的结果集作为objectiative数组。 mysql_fetch_object语法:array mysql_fetch_object (resource $Result_Set) ……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2714浏览 269个赞
php查询mysql数据库并将结果保存到数组主要用到了mysql_fetch_assoc函数mysql_fetch_assoc语法如下:array mysql_fetch_assoc (resource $Result_Set){-范例代码如下--}<?php$UserName = 'abc';$Passwo……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2639浏览 353个赞
PHP gmdate –将一个UNIX 时间格式化成 GMT 文本 语法如下:string gmdate (string $Format)string gmdate (string $Format, int $Time) ……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1952浏览 871个赞
PHP time 函数– 得到当前时间的时间戳,输出格式为整数输出结果为从1970年1月1日到当前时间的秒数<?php $Now = time(); echo 'When this page was loaded, <br>';echo "$Now seconds had elapsed sin……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3000浏览 2480个赞
php从文件读取json数据的简单范例$file = new File('/path/to/file');$myjson = $file->read(true, 'r');$myjsonarray = json_decode($json);……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3637浏览 1140个赞
php使用unlink删除文件<?php // deletefile.phpif (!unlink('testfile.txt')) echo "Could not delete file";else echo "File 'testfile' successfully de……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2632浏览 881个赞
通过这些校验函数可以很容易的验证数据是否是执行的类型is_array() – Test for Arraysis_bool() – Test for Booleans (TRUE, FALSE)is_float() – Test for Floating-point numbersis_int() – Test for Integersis_nu……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3351浏览 744个赞
PHP文件上传时 $_FILES 数据的内容$_FILES['file']['name'] 上传文件的名字 (e.g., somefile.jpg)$_FILES['file']……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3247浏览 827个赞
php图片上传范例代码<?php // upload.phpecho <<<_END<html><head><title>PHP Form Upload</title></head><body><form method='post……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2597浏览 1604个赞
php复制文件的语法,使用copy函数<?php // copyfile2.phpif (!copy('testfile.txt', 'testfile2.txt')) echo "Could not copy file";else echo "File successful……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1623浏览 1254个赞
php修改服务器上的文件代码范例<?php // update.php$fh = fopen("testfile.txt", 'r+') or die("Failed to open file");$text = fgets($fh);fseek($fh, 0, SEEK_END);……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1622浏览 1485个赞
php将json数据写入到文件的范例代码$json = '{"key":"value"}';$file = new File('/path/to/file', true);$file->write($json);……继续阅读 » 水墨上仙 5年前 (2021-03-20) 4469浏览 1695个赞
php链接到mysql数据库,最后关闭链接的代码演示用mysql_connect链接到数据库,用mysql_close关闭数据库<?php $UserName = 'abc';$Password = '8sj27s';$DbHandle = mysql_connect ('localhos……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2246浏览 2005个赞
php链接mysql数据库并作简单的查询<?php$UserName = 'abc';$Password = '1234';$DbHandle = mysql_connect ('localhost', $UserName, $Password);if (!$DbHandle) {……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2854浏览 2662个赞
php 中用fread读取文件的代码演示<?php$fh = fopen("testfile.txt", 'r') ordie("File does not exist or you lack permission to open it");$text = fread($fh, 3)……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1550浏览 758个赞
php链接到mysql的简单示例需要提供mysql的服务器地址,用户名和密码,这里mysql装在本机,所以使用localhost<?php $UserName = 'abc';$Password = '8sj27s';$DbHandle = mysql_connect ('localhos……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2154浏览 995个赞
php中通过 $_SESSION保存session变量,下面的代码简单演示了 $_SESSION的用法<?php session_start(); print("<html><b>"); $_SESSION["sitename"] = "W3M";……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2402浏览 1305个赞
SimpleXML 是一个php扩展,有了它可以非常容易的操作xml文件class CI_ManipulateXML{ var $xml=''; function CI_ManipulateXML($xmlcontent){ $this->xml=$xmlcontent;} function ConvertX……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3048浏览 1197个赞
php Codeigniter发送邮件Codeigniter的邮件发送支持一下特性:Multiple Protocols: Mail, Sendmail, and SMTPMultiple recipientsCC and BCCsHTML or Plaintext emailAttachmentsWord wrappingPrioritie……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1903浏览 472个赞
attach() 方法允许你的发邮件时带上附件,下面是演示代码$this->load->library('email');$this->email->from('w3@w3mentor.com', 'W3M');$this->email->subject(……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1897浏览 2259个赞
PHP日期函数 – 格式化一个UNIX时间为文本日期函数可以根据指定的格式将一个unix时间格式化成想要的文本输出 使用到函数语法如下string date (string $Format);string date (string $Format, int $Tim……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2241浏览 2086个赞
PHP GETDATE函数是用来获得当前的日期和时间,从操作系统或一个关联数组转换成UNIX风格的日期整数。 语法格式如下array getdate ();array getdate (integer $Time); ……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1939浏览 2167个赞
有两种方法可以得到用户的session id,第一是使用session_id()函数,另外一种是使用内置的常量SID获得,SID包含了session id和session值<?php session_start(); print("<html><b>"); $sid = session_i……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2554浏览 1813个赞
通过组合.htaccess文件和.htpasswd文件被用来阻止用户访问某些服务器上的目录。这些文件包含有关用户被允许访问一个目录和自己的密码信息。 HTTP身份验证可以通过发送特殊的HTTP header信息,而不用使用.htaccess文件<?php if (!isset($_SERVER['PHP_AUTH_USER……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2364浏览 767个赞
php中可以使用checkdate函数校验日期的正确性。 语法integer checkdate (int %Month, int $Day, int $Year); 演示代码<?PHP ……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2960浏览 707个赞
php gettimeofday函数-返回当前时间存放在关联数组里Key Descriptionsec Seconds since midnight before January 1, 1970usec  Microsecond……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3395浏览 2329个赞
php表单同时上传多个文件的方法,下面提供了两种方法,一种通过文件数组,第二种通过不同的变量 方法1:在html表单, 放置多个文件选择框, 使用数组名作为组件的名字, 如下:<form action="up……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1992浏览 678个赞
php中使用switch分支语句范例 <?php//Initializing variables$a = 10;$b = 5;echo("1. Addition <br>");echo("2. Subtraction <br>");echo("3. Multipl……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2680浏览 1905个赞
最简单的方法如下,直接通过file_get_contents获取远程内容,然后通过json_decode解码$data = json_decode( file_get_contents(“http://www.w3mentor.com/service.json”));……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2403浏览 1553个赞
php中可以在函数内部内嵌一个函数,调用范围仅限于函数本身<?phpfunction msg(){ echo("<center><h2>Displaying even numbers</h2></center><p><p>"); fun……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2761浏览 1805个赞
php中while语句使用范例<?php$a=2;echo("<p>Even Numbers from 2 to 30<p>");while ($a <=30){ echo("$a <br>"); $a=$a+2;}?>……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2634浏览 1743个赞
php中使用自定义错误处理<?phperror_reporting(E_ALL);function ErrHandler($errorno, $errorstr, $errorfile, $errorline) { $display = true; $notify = false; $halt_script = false;……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2651浏览 193个赞
php中通过fget读取文件<?php$fh = fopen("testfile.txt", 'r') ordie("File does not exist or you lack permission to open it");$line = fgets($fh);fclose(……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3278浏览 2030个赞
php中可以使用file_exists函数检测文件是否存在,如果存在返回True,否则返回Falseif (file_exists("somefile.txt")) echo "File exists";……继续阅读 » 水墨上仙 5年前 (2021-03-20) 4629浏览 2981个赞
php创建一个简单的文本文件1. 使用fopen以写入模式(w)打开文件2. 使用fwrite写入文件3.通过fclose关闭文件<?php // testfile.php$fh = fopen("testfile.txt", 'w') or die("Failed to create fi……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3074浏览 2796个赞
这段代码用于上传图片,可以根据图片类型检测图片是否安全,不是简单的检测扩展名<?php // upload.phpecho <<<_END<html><head><title>PHP Form Upload</title></head><body><……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3439浏览 2179个赞
php实现的一个通用的从数据库表读取数据到数组的函数,此函数不关心表结构,只需要指定表名、结构和查询条件既可以对表进行通用查询操作,非常实用。function listmytablerows($table, $name, $field, $where, $textID){/ / Connect to the database and query ex……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3089浏览 2083个赞
php在一个cookie中存储多个值得代码演示<?php$info = array("xyz", "yellow", 22);setcookie("usr", serialize($info));?><html><head><title>M……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1752浏览 2565个赞
在php中执行系统命令,如LS<?php // exec.php$cmd = "dir"; // Windows// $cmd = "ls"; // Linux, Unix & Macexec(escapeshellcmd($cmd), $output, $status);if ($statu……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1891浏览 1661个赞
php读取并显示文本文件内容 <?php$file='info.txt';$fobj=fopen($file,"r");$text=fread($fobj, filesize($file));echo("<h2><font color='blue'&g……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2149浏览 505个赞
php 类定义和类实例使用范例<?phpclass emp{ var $name; var $address; var $dept; function assign_info($n,$a,$d) { $this->name=$n; $this->state=$a; $……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1715浏览 1592个赞
PHP Codeigniter校验用户email地址,Codeigniter内置了email检验的函数,使用非常简单$email = $this->input->post('email') ;if( ! valid_email($email) ){ show_404 ("The email address……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2709浏览 2772个赞