php通过array_merge()函数合并两个数组,array_merge()是一个php函数,用于将两个或者多个数组合并,后一个数组会追加到前一个数组后面,并返回结果数组。它接受两个或两个以上的数组,并返回一个包含了所有元素的数组。$first = array("aa", "bb", "cc"……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2683浏览 1373个赞
array_merge()是一个用于合并数组的php函数,后一个数组追加到前一个的结束位置并返回合并后的结果数组。<?php$beginning = 'foo';$end = array(1 => 'bar');$result = array_merge((array)$beginning, (a……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2204浏览 377个赞
php中可以通过count()函数返回数组的长度,即数组元素个数,由于php数组的元素索引是从0开始计数的,所以count()函数不能返回数组中最后一个元素的索引号,需要减去1,下面的代码返回$users数组的最后一个元素的索引号$users = array ("qdv.cn", "haotu.net", &quo……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1984浏览 2287个赞
php真的是非常的灵活,定义数组也是非常的方便 方法1,可以通过下面的方式定义数组$users[],php会自动维护索引号:$users[] = "mani";$users[] = "nani";$users[] = "mad&……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1780浏览 2015个赞
PHP提供了一个名为array_fill()的函数用来给数组填充默认值,array_fill()函数有三个参数:第一个是数字,代表开始填充的索引号,第二个整数,代表要填充的元素数量,第三个参数是要添加到数组中的值。 使用范例,下面的代码表示给$usertype数组0-4的位置填充7527……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2824浏览 1226个赞
end()函数在PHP中用于检索数组中的最后一个元素。end()函数需要一个数组作为其唯一参数,并返回给定的数组的最后一个元素。$users = array ("52ebook.com", "haotu.net", "qdv.cn", "75271.com");print ……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3075浏览 1581个赞
使用PHP的strtotime计算两个给定日期之间的天数PHP的strtotime函数用于将任何英文文本的日期时间描述解析为Unix时间戳。这个函数将使用TZ环境变量(如果有的话)来计算时间戳。如果执行成功它返回一个时间戳,否则返回FALSE。在PHP 5.1.0之前,这个函数将返回-1。$date1 = date(‘Y-m-d’);$date2 =……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1587浏览 802个赞
mysql_num_fields用于获得查询结果的列数,如果执行成功返回列数,执行失败,返回boolean值<?php$UserName = 'abc';$Password = '1234';$DbHandle = mysql_connect ('localhost', $UserN……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3200浏览 200个赞
mysql_fetch_row用于从mysql数据库中查询数据,并保存到list中 语法如下:array mysql_fetch_row (resource $Result_Set) 如果执行成功,则返回l……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2796浏览 2662个赞
mysql_fetch_object函数用于,提取结果行从一个MySQL的结果集作为objectiative数组。 mysql_fetch_object语法:array mysql_fetch_object (resource $Result_Set) ……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2624浏览 914个赞
php查询mysql数据库并将结果保存到数组主要用到了mysql_fetch_assoc函数mysql_fetch_assoc语法如下:array mysql_fetch_assoc (resource $Result_Set){-范例代码如下--}<?php$UserName = 'abc';$Passwo……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2670浏览 1166个赞
PHP gmdate –将一个UNIX 时间格式化成 GMT 文本 语法如下:string gmdate (string $Format)string gmdate (string $Format, int $Time) ……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2946浏览 638个赞
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) 2836浏览 969个赞
php从文件读取json数据的简单范例$file = new File('/path/to/file');$myjson = $file->read(true, 'r');$myjsonarray = json_decode($json);……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3560浏览 2932个赞
php使用unlink删除文件<?php // deletefile.phpif (!unlink('testfile.txt')) echo "Could not delete file";else echo "File 'testfile' successfully de……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3058浏览 2861个赞
通过这些校验函数可以很容易的验证数据是否是执行的类型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) 2420浏览 2954个赞
PHP文件上传时 $_FILES 数据的内容$_FILES['file']['name'] 上传文件的名字 (e.g., somefile.jpg)$_FILES['file']……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2060浏览 746个赞
php图片上传范例代码<?php // upload.phpecho <<<_END<html><head><title>PHP Form Upload</title></head><body><form method='post……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1486浏览 1262个赞
php复制文件的语法,使用copy函数<?php // copyfile2.phpif (!copy('testfile.txt', 'testfile2.txt')) echo "Could not copy file";else echo "File successful……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2101浏览 2692个赞
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) 3173浏览 2143个赞
php将json数据写入到文件的范例代码$json = '{"key":"value"}';$file = new File('/path/to/file', true);$file->write($json);……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3192浏览 2152个赞
php链接到mysql数据库,最后关闭链接的代码演示用mysql_connect链接到数据库,用mysql_close关闭数据库<?php $UserName = 'abc';$Password = '8sj27s';$DbHandle = mysql_connect ('localhos……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2109浏览 1380个赞
php链接mysql数据库并作简单的查询<?php$UserName = 'abc';$Password = '1234';$DbHandle = mysql_connect ('localhost', $UserName, $Password);if (!$DbHandle) {……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2092浏览 1079个赞
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) 2396浏览 928个赞
php链接到mysql的简单示例需要提供mysql的服务器地址,用户名和密码,这里mysql装在本机,所以使用localhost<?php $UserName = 'abc';$Password = '8sj27s';$DbHandle = mysql_connect ('localhos……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2406浏览 2480个赞
php中通过 $_SESSION保存session变量,下面的代码简单演示了 $_SESSION的用法<?php session_start(); print("<html><b>"); $_SESSION["sitename"] = "W3M";……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2494浏览 1657个赞
SimpleXML 是一个php扩展,有了它可以非常容易的操作xml文件class CI_ManipulateXML{ var $xml=''; function CI_ManipulateXML($xmlcontent){ $this->xml=$xmlcontent;} function ConvertX……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2665浏览 2074个赞
php Codeigniter发送邮件Codeigniter的邮件发送支持一下特性:Multiple Protocols: Mail, Sendmail, and SMTPMultiple recipientsCC and BCCsHTML or Plaintext emailAttachmentsWord wrappingPrioritie……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2762浏览 2902个赞
attach() 方法允许你的发邮件时带上附件,下面是演示代码$this->load->library('email');$this->email->from('w3@w3mentor.com', 'W3M');$this->email->subject(……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1704浏览 701个赞
PHP日期函数 – 格式化一个UNIX时间为文本日期函数可以根据指定的格式将一个unix时间格式化成想要的文本输出 使用到函数语法如下string date (string $Format);string date (string $Format, int $Tim……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3072浏览 2143个赞
PHP GETDATE函数是用来获得当前的日期和时间,从操作系统或一个关联数组转换成UNIX风格的日期整数。 语法格式如下array getdate ();array getdate (integer $Time); ……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3010浏览 372个赞
有两种方法可以得到用户的session id,第一是使用session_id()函数,另外一种是使用内置的常量SID获得,SID包含了session id和session值<?php session_start(); print("<html><b>"); $sid = session_i……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1914浏览 2497个赞
通过组合.htaccess文件和.htpasswd文件被用来阻止用户访问某些服务器上的目录。这些文件包含有关用户被允许访问一个目录和自己的密码信息。 HTTP身份验证可以通过发送特殊的HTTP header信息,而不用使用.htaccess文件<?php if (!isset($_SERVER['PHP_AUTH_USER……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2059浏览 1113个赞
php中可以使用checkdate函数校验日期的正确性。 语法integer checkdate (int %Month, int $Day, int $Year); 演示代码<?PHP ……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1769浏览 2734个赞
php gettimeofday函数-返回当前时间存放在关联数组里Key Descriptionsec Seconds since midnight before January 1, 1970usec  Microsecond……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1731浏览 233个赞
php表单同时上传多个文件的方法,下面提供了两种方法,一种通过文件数组,第二种通过不同的变量 方法1:在html表单, 放置多个文件选择框, 使用数组名作为组件的名字, 如下:<form action="up……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2548浏览 1143个赞
php中使用switch分支语句范例 <?php//Initializing variables$a = 10;$b = 5;echo("1. Addition <br>");echo("2. Subtraction <br>");echo("3. Multipl……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3010浏览 2123个赞
最简单的方法如下,直接通过file_get_contents获取远程内容,然后通过json_decode解码$data = json_decode( file_get_contents(“http://www.w3mentor.com/service.json”));……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2662浏览 2568个赞
php中可以在函数内部内嵌一个函数,调用范围仅限于函数本身<?phpfunction msg(){ echo("<center><h2>Displaying even numbers</h2></center><p><p>"); fun……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2600浏览 2471个赞
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) 3643浏览 1329个赞
php中使用自定义错误处理<?phperror_reporting(E_ALL);function ErrHandler($errorno, $errorstr, $errorfile, $errorline) { $display = true; $notify = false; $halt_script = false;……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2098浏览 839个赞
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) 3056浏览 460个赞
php中可以使用file_exists函数检测文件是否存在,如果存在返回True,否则返回Falseif (file_exists("somefile.txt")) echo "File exists";……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3331浏览 344个赞
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) 3354浏览 2611个赞
这段代码用于上传图片,可以根据图片类型检测图片是否安全,不是简单的检测扩展名<?php // upload.phpecho <<<_END<html><head><title>PHP Form Upload</title></head><body><……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1995浏览 1524个赞