浪潮实习第八天

今天又对一大堆的开源的cms和在线文件管理器进行了试用,有时候过多的选择也是一种烦恼抓狂,可能是星期五的原因,下午有点浮躁,看不进去新东西,老是东张西望。从网上下载了一个php的数据结构开源包,研究了一下下,架构和算法都写得很棒。我什么时候才能达到那种水平委屈。下载了eclipse for cpp,把以前下载的c开源库放到里面,可不知为神马还是有很多的错误,不过至少可以比较快速的浏览某个函数的定义了,所以比较高兴,今天做的笔记如下:

1.判断一个文件是否存在,若存在则跳转

file_exists('install.php')&& header('Location: ./install.php');

2.require_once是导入脚本并执行,相当于#program once;

3.in_array用于检查数组中是否存在某个值

4.floor舍去法取整

5.cookie的用法,setcookie为设置某一cookie,$_COOKIE[]为获取cookie的值

6.is_object用来判断某一变量是否为对象

7.再用query从数据库取得数据库数据后,可用mysql_fetch_array函数从结果集中取一行作为关联数组。

8.list作用是将数组中的值赋给一些变量,如

$info=array('coffee','brown','caffeine');

//Listingallthevariables
list($drink,$color,$power)=$info;
echo"$drinkis$colorand$powermakesitspecial.\n";

9. 禁止直接访问某一文件

//禁止直接访问此文件,若直接访问直接退出显示Forbidden
!function_exists('readover') &&exit('Forbidden');

10.要销毁cookie,直接设置该cookie的某一属性键值为0即可

11.判断一个字符串是否在另一个字符串中,可用strpos函数,用法如下:

$mystring='abc';
$findme='a';
$pos=strpos($mystring,$findme);

//Noteouruseof===.Simply==wouldnotworkasexpected
//becausethepositionof'a'wasthe0th(first)character.
if($pos===false){
echo"Thestring'$findme'wasnotfoundinthestring'$mystring'";
}else{
echo"Thestring'$findme'wasfoundinthestring'$mystring'";
echo"andexistsatposition$pos";
}

12.可通过flock对打开的文件句柄进行锁定,然后通过flock+un参数进行解锁,也可通过fclose进行解锁

13.touch函数可以设置文件的修改时间为调用touch时的时间

14.ord函数返回ascii码的数字值

15.遍历有键值的数组的惯用方法如下:

foreach($array as $key=>$value){}

16. 引用在php中意味着用不同的名字访问同一变量内容

17.array_rand从数组中随机取出一个或多个元素,例子如下

<?php
srand((float)microtime()*10000000);
$input=array("Neo","Morpheus","Trinity","Cypher","Tank");
$rand_keys=array_rand($input,2);
print$input[$rand_keys[0]]."\n";
print$input[$rand_keys[1]]."\n";
?>

18.sort函数可以对数组进行排序,rsort为反序排序

19.chr函数根据数字返回相应的ascii码。

20,两个有序数组合并为一个数组(和平常的不一样,效率。。。。。)

/**

* Merges two sorted subsequences of thearray into one.

* @param integer $left The firstposition of the left subsequence.

* @param integer $middle The firstposition of the right subsequence.

* The last position in the leftsubsequences is middle-1.

* @param integer $right The lastposition of the right subsequence.

*/

protected function merge($left,$middle, $right)

{

$i = $left;

$j = $left;

$k = $middle + 1;

while ($j <= $middle && $k<= $right)

{

if (lt($this->array[$j], $this->array[$k]))

$this->tempArray[$i++] = $this->array[$j++];

else

$this->tempArray[$i++] = $this->array[$k++];

}

while ($j <= $middle)

$this->tempArray[$i++] = $this->array[$j++];

for ($i = $left; $i < $k; ++$i)

$this->array[$i] = $this->tempArray[$i];

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值