php常见函数汇总
<p align="left"><strong>1.abs(): </strong><strong>求绝对值</strong></p><p align="left">$abs = abs(-4.2); //4.2 数字绝对值数字</p>
<p align="left"><strong>2.ceil(): </strong><strong>进一法取整</strong></p>
<p align="left">echo ceil(9.999); // 10 浮点数进一取整</p>
<p align="left"><strong>3.floor(): </strong><strong>舍去法取整</strong></p>
<p align="left"> echo floor(9.999); // 9 浮点数直接舍去小数部分</p>
<p align="left"><strong>4.fmod(): </strong><strong>浮点数取余</strong></p>
<table style="width: 581px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
</td>
<td width="552">
<p align="left">$x = 5.7;</p>
<p align="left">$y = 1.3; // 两个浮点数,x>y 浮点余数</p>
<p align="left">$r = fmod($x, $y);</p>
<p align="left">// $r equals 0.5, because 4 * 1.3 + 0.5 = 5.7</p>
</td>
</tr>
</tbody>
</table>
<p align="left"><strong>5.pow(): </strong><strong>返回数的</strong><strong>n</strong><strong>次方</strong></p>
<p align="left"> echo pow(-1, 20); // 1 基础数|n次方乘方值</p>
<p align="left"><strong>6.round(): </strong><strong>浮点数四舍五入</strong></p>
<p align="left"> echo round(1.95583, 2); // 1.96, 一个数值|保留小数点后多少位,默认为0 舍入后的结果</p>
<p align="left"><strong>7.sqrt(): </strong><strong>求平方根</strong></p>
<p align="left"> echo sqrt(9); //3 被开方的数平方根</p>
<p align="left"><strong>8.max(): </strong><strong>求最大值</strong></p>
<p align="left"> echo max(1, 3, 5, 6, 7); // 7</p>
<p align="left">多个数字或数组 返回其中的最大值</p>
<p align="left"> echo max(array(2, 4, 5)); // 5</p>
<p align="left"><strong>9.min(): </strong><strong>求最小值</strong></p>
<p align="left">输入: 多个数字或数组</p>
<p align="left">输出: 返回其中的最小值</p>
<p align="left"><strong>10.mt_rand(): </strong><strong>更好的随机数</strong></p>
<p align="left">输入: 最小|最大, 输出: 随机数随机返回范围内的值</p>
<p align="left">echo mt_rand(0,9);//n</p>
<p align="left"><strong>11.rand(): </strong><strong>随机数</strong><strong>输入</strong><strong>: </strong><strong>最小</strong><strong>|</strong><strong>最大</strong><strong>, </strong><strong>输出</strong><strong>: </strong><strong>随机数随机返回范围内的值</strong></p>
<p align="left"><strong>12.pi(): </strong><strong>获取圆周率值</strong></p>
<p align="left">去空格或或其他字符:</p>
<p align="left"><strong>13.trim(): </strong><strong>删除字符串两端的空格或其他预定义字符</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$str = "\r\nHello World!\r\n";</p>
<p align="left">echo trim($str);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">输入: 目标字符串 返回值: 清除后的字符串</p>
<p align="left"><strong>14.rtrim(): </strong><strong>删除字符串右边的空格或其他预定义字符</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$str = "Hello World!\n\n";</p>
<p align="left">echo rtrim($str);</p>
</td>
</tr>
</tbody>
</table>
<p align="left"><strong>15.chop(): rtrim()</strong><strong>的别名</strong></p>
<p align="left"><strong>16.ltrim(): </strong><strong>删除字符串左边的空格或其他预定义字符</strong></p>
<p align="left"> </p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$str = "\r\nHello World!";</p>
<p align="left">echo ltrim($str);</p>
</td>
</tr>
</tbody>
</table>
<p align="left"><strong>17.dirname(): </strong><strong>返回路径中的目录部分</strong></p>
<p align="left"> echo dirname("c:/testweb/home.php"); //c:/testweb<br>
输入: 一个包含路径的字符串 返回值: 返回文件路径的目录部分</p>
<p align="left">字符串生成与转化: </p>
<p align="left"><strong>18.str_pad(): </strong><strong>把字符串填充为指定的长度</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$str =
"Hello World";</p>
<p align="left">echo str_pad($str,20,".");</p>
</td>
</tr>
</tbody>
</table>
<p align="left">输入: 要填充的字符串|新字符串的长度|供填充使用的字符串, 默认是空白</p>
<p align="left">输出: 完成后的字符串</p>
<p align="left"><strong>19.str_repeat(): </strong><strong>重复使用指定字符串</strong></p>
<p align="left"> echo
str_repeat(".",13); // 要重复的字符串|字符串将被重复的次数13个点<br>
<strong>20.str_split(): </strong><strong>把字符串分割到数组中</strong></p>
<p align="left">print_r(str_split("Hello"));<br>
输入: 要分割的字符串|每个数组元素的长度,默认1</p>
<p align="left">输出: 拆分后的字符串数组</p>
<p align="left"><strong>21.strrev(): </strong><strong>反转字符串</strong></p>
<p align="left"> echo
strrev("Hello World!"); // !dlroW olleH<br>
输出: 目标字符串颠倒顺序后的字符串</p>
<p align="left"><strong>22.wordwrap(): </strong><strong>按照指定长度对字符串进行折行处理</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
</td>
<td width="405">
<p align="left">$str =
"An example on a long word is:</p>
<p align="left">Supercalifragulistic";</p>
<p align="left">echo wordwrap($str,15);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">输入: 目标字符串|最大宽数</p>
<p align="left">输出: 折行后的新字符串</p>
<p align="left"><strong>23.str_shuffle(): </strong><strong>随机地打乱字符串中所有字符</strong></p>
<p align="left"> echo
str_shuffle("Hello World");<br>
输入: 目标字符串顺序 输出: 打乱后的字符串</p>
<p align="left"><strong>24.parse_str(): </strong><strong>将字符串解析成变量</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">parse_str("id=23&name=John%20Adams",
$myArray);</p>
<p align="left">print_r($myArray);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">输入: 要解析的字符串|存储变量的数组名称</p>
<p align="left">输出: 返回Array( => 23 => John Adams)</p>
<p align="left"><strong>25.number_format(): </strong><strong>通过千位分组来格式化数字</strong><strong>输入</strong><strong>: </strong><strong>要格式化的数字</strong><strong>|</strong><strong>规定多少个小数</strong><strong>|</strong><strong>规定用作小数点的字符</strong><strong>串</strong><strong>|</strong><strong>规定用作千位分隔符的字符串</strong></p>
<p align="left">输出: 1,000,000
1,000,000.00 1.000.000,00</p>
<p align="left">大小写转换:</p>
<p align="left"><strong>26.strtolower(): </strong><strong>字符串转为小写</strong></p>
<p align="left"> echo
strtolower("Hello WORLD!");<br>
目标字符串 小写字符串</p>
<p align="left"><strong>27.strtoupper(): </strong><strong>字符串转为大写</strong></p>
<p align="left"> echo
strtoupper("Hello WORLD!");<br>
输出: 大写字符串</p>
<p align="left"><strong>28.ucfirst(): </strong><strong>字符串首字母大写</strong></p>
<p align="left"> echo
ucfirst("hello world"); // Hello world<br>
<strong>29.ucwords(): </strong><strong>字符串每个单词首字符转为大写</strong></p>
<p align="left"> echo
ucwords("hello world"); // Hello World<br>
html标签关联:</p>
<p align="left"><strong>30.htmlentities(): </strong><strong>把字符转为</strong><strong>HTML</strong><strong>实体</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$str =
"John & 'Adams'";</p>
<p align="left">echo htmlentities($str,
ENT_COMPAT); // John & 'Adams'</p>
</td>
</tr>
</tbody>
</table>
<p align="left"><strong>31.htmlspecialchars(): </strong><strong>预定义字符转</strong><strong>html</strong><strong>编码</strong></p>
<p align="left"><strong>32.nl2br(): \n</strong><strong>转义为</strong><strong><br></strong><strong>标签</strong></p>
<p align="left"> echo nl2br("One
line.\nAnother line.");<br>
输出: 处理后的字符串</p>
<p align="left"><strong>33.strip_tags(): </strong><strong>剥去</strong><strong> HTML</strong><strong>、</strong><strong>XML </strong><strong>以及</strong><strong> PHP </strong><strong>的标签</strong></p>
<p align="left"> echo
strip_tags("Hello <b>world!</b>"); <br>
<strong>34.addcslashes():</strong><strong>在指定的字符前添加反斜线转义字符串中字符</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
</td>
<td width="405">
<p align="left">$str =
"Hello, my name is John Adams.";</p>
<p align="left">echo $str;</p>
<p align="left">echo addcslashes($str,'m');</p>
</td>
</tr>
</tbody>
</table>
<p align="left">输入: 目标字符串|指定的特定字符或字符范围</p>
<p align="left"><strong>35.stripcslashes(): </strong><strong>删除由</strong><strong>addcslashes()</strong><strong>添加的反斜线</strong></p>
<p align="left"> echo
stripcslashes("Hello, \my na\me is Kai Ji\m.");<br>
// 目标字符串 Hello, my name is Kai Jim.<br>
<strong>36.addslashes(): </strong><strong>指定预定义字符前添加反斜线</strong></p>
<p align="left"> $str = "Who's
John Adams?";<br>
echo addslashes($str);<br>
输出: 把目标串中的' " \和null进行转义处理</p>
<p align="left"><strong>37.stripslashes(): </strong><strong>删除由</strong><strong>addslashes()</strong><strong>添加的转义字符</strong></p>
<p align="left"> echo
stripslashes("Who\'s John Adams?"); // 清除转义符号Who's John
Adams?<br>
<strong>38.quotemeta(): </strong><strong>在字符串中某些预定义的字符前添加反斜线</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
</td>
<td width="405">
<p align="left">$str =
"Hello world. (can you hear me?)";</p>
<p align="left">echo quotemeta($str);</p>
<p align="left"> // Hello world\. \(can you hear me\?\)</p>
</td>
</tr>
</tbody>
</table>
<p align="left"><strong>39.chr(): </strong><strong>从指定的</strong><strong> ASCII </strong><strong>值返回字符</strong></p>
<p align="left"> echo chr(052); //
ASCII 值返回对应的字符<br>
<strong>40.ord(): </strong><strong>返回字符串第一个字符的</strong><strong>ASCII</strong><strong>值</strong></p>
<p align="left"> echo
ord("hello"); 字符串第一个字符的 ASCII 值<br>
字符串比较:</p>
<p align="left"><strong>41.strcasecmp(): </strong><strong>不区分大小写比较两字符串</strong></p>
<p align="left"> echo
strcasecmp("Hello world!","HELLO WORLD!");<br>
输入: 两个目标字符串 输出: 大1|等0|小 -1</p>
<p align="left"><strong>42.strcmp(): </strong><strong>区分大小写比较两字符串</strong></p>
<p align="left"><strong>43.strncmp(): </strong><strong>比较字符串前</strong><strong>n</strong><strong>个字符</strong><strong>,</strong><strong>区分大小写</strong></p>
<p align="left">调用: int strncmp (
string $str1 , string $str2 , int $len) </p>
<p align="left"> <strong>44.strncasecmp(): </strong><strong>比较字符串前</strong><strong>n</strong><strong>个字符</strong><strong>,</strong><strong>不区分大小写</strong></p>
<p align="left">调用: int
strncasecmp ( string $str1 , string $str2 , int $len )</p>
<p align="left"><strong>45.strnatcmp(): </strong><strong>自然顺序法比较字符串长度</strong><strong>,</strong><strong>区分大小写</strong></p>
<p align="left">调用: int strnatcmp
( string $str1 , string $str2 )</p>
<p align="left">输入: 目标字符串 </p>
<p align="left"><strong>46.strnatcasecmp(): </strong><strong>自然顺序法比较字符串长度</strong><strong>, </strong><strong>不区分大小写</strong></p>
<p align="left">调用: int
strnatcasecmp ( string $str1 , string $str2 )</p>
<p align="left">字符串切割与拼接:</p>
<p align="left"><strong>47.chunk_split()</strong><strong>:将字符串分成小块</strong></p>
<p align="left">调用: str
chunk_split(str $body[,int $len[,str $end]])</p>
<p align="left">输入: $body目标字串, $len长度, $str插入结束符 输出: 分割后的字符串</p>
<p align="left"><strong>48.strtok(): </strong><strong>切开字符串</strong></p>
<p align="left">调用: str strtok(str
$str,str $token)</p>
<p align="left">目标字符串$str,以$token为标志切割返回切割后的字符串</p>
<p align="left"><strong>49.explode(): </strong><strong>使用一个字符串为标志分割另一个字符串</strong></p>
<p align="left">调用: array
explode(str $sep,str $str[,int $limit])</p>
<p align="left">输入: $sep为分割符,$str目标字符串,$limit返回数组最多包含元素数 输出: 字符串被分割后形成的数组</p>
<p align="left"><strong>50.implode(): </strong><strong>同</strong><strong>join,</strong><strong>将数组值用预订字符连接成字符串</strong></p>
<p align="left">调用: string implode
( string $glue , array $pieces )</p>
<p align="left">$glue默认, 用''则直接相连</p>
<p align="left"><strong>51.substr(): </strong><strong>截取字符串</strong></p>
<p align="left">调用: string substr
( string $string , int $start [, int $length ] )</p>
<p align="left">字符串查找替换:</p>
<p align="left"><strong>52.str_replace(): </strong><strong>字符串替换操作</strong><strong>,</strong><strong>区分大小写</strong></p>
<p align="left">调用mix
str_replace(mix $search,mix $replace, mix $subject[,int &$num])</p>
<p align="left">输入: $search查找的字符串,$replace替换的字符串,$subject被查找字串, &$num 输出: 返回替换后的结果</p>
<p align="left"><strong>53.str_ireplace() </strong><strong>字符串替换操作</strong><strong>,</strong><strong>不区分大小写</strong></p>
<p align="left">调用: mix
str_ireplace ( mix $search , mix $replace , mix $subject [, int &$count ] )</p>
<p align="left">输入: $search查找的字符串,$replace替换的字符串,$subject被查找字串,&$num 输出: 返回替换后的结果</p>
<p align="left"><strong>54.substr_count(): </strong><strong>统计一个字符串</strong><strong>,</strong><strong>在另一个字符串中出现次数</strong></p>
<p align="left">调用: int
substr_count ( string $haystack , string $needle[, int $offset = 0 [, int
$length ]] )</p>
<p align="left"><strong>55.substr_replace(): </strong><strong>替换字符串中某串为另一个字符串</strong></p>
<p align="left">调用: mixed
substr_replace ( mixed $string, string $replacement,int $start [, int $length ]
)</p>
<p align="left"><strong>56.similar_text(): </strong><strong>返回两字符串相同字符的数量</strong></p>
<p align="left">调用: int
similar_text(str $str1,str $str2)<br>
输入: 两个比较的字符串</p>
<p align="left">输出: 整形,相同字符数量</p>
<p align="left"><strong>57.strrchr(): </strong><strong>返回一个字符串在另一个字符串中最后一次出现位置开始到末尾的字符串</strong></p>
<p align="left">调用: string strrchr
( string $haystack , mixed $needle )</p>
<p align="left"><strong>58.strstr(): </strong><strong>返回一个字符串在另一个字符串中开始位置到结束的字符串</strong></p>
<p align="left">调用: string strstr
( string $str, string $needle , bool $before_needle ) </p>
<p align="left"> <strong>59.strchr(): strstr()</strong><strong>的别名</strong><strong>,</strong><strong>返回一个字符串在另一个字符串中首次出现的位置开始到末尾的字符串</strong></p>
<p align="left">调用: string strstr
( string $haystack , mixed $needle [, bool $before_needle = false ] ) </p>
<p align="left"><strong>60.stristr(): </strong><strong>返回一个字符串在另一个字符串中开始位置到结束的字符串,不区分大小写</strong></p>
<p align="left">调用:string stristr
( string $haystack , mixed $needle [, bool $before_needle = false ] )</p>
<p align="left"><strong>61.strtr(): </strong><strong>转换字符串中的某些字符</strong></p>
<p align="left">调用: string strtr (
string $str , string $from , string $to )</p>
<p align="left"><strong>62.strpos(): </strong><strong>寻找字符串中某字符最先出现的位置</strong></p>
<p align="left">调用: int strpos (
string $haystack , mixed $needle [, int $offset = 0 ] )</p>
<p align="left"><strong>63.stripos(): </strong><strong>寻找字符串中某字符最先出现的位置</strong><strong>,</strong><strong>不区分大小写</strong><strong>调用</strong><strong>: int stripos (
string $haystack , string $needle [, int $offset ] )</strong></p>
<p align="left"><strong>64.strrpos(): </strong><strong>寻找某字符串中某字符最后出现的位置</strong></p>
<p align="left">调用: int strrpos (
string $haystack , string $needle [, int $offset = 0 ] )</p>
<p align="left"><strong>65.strripos(): </strong><strong>寻找某字符串中某字符最后出现的位置</strong><strong>,</strong><strong>不区分大小写</strong></p>
<p align="left">调用: int strripos (
string $haystack , string $needle [, int $offset ] )</p>
<p align="left"><strong>66.strspn(): </strong><strong>返回字符串中首次符合</strong><strong>mask</strong><strong>的子字符串长度</strong><strong>调用</strong><strong>: int strspn (
string $str1 , string $str2 [, int $start [, int $length ]] )</strong></p>
<p align="left"><strong>67.strcspn(): </strong><strong>返回字符串中不符合</strong><strong>mask</strong><strong>的字符串的长度</strong></p>
<p align="left">调用: int strcspn (
string $str1 , string $str2 [, int $start [, int $length ]] )</p>
<p align="left">输入: $str1被查询,$str2查询字符串,$start开始查询的字符,$length是查询长度 输出: 返回从开始到第几个字符</p>
<p align="left">字符串统计:</p>
<p align="left"><strong>68.str_word_count(): </strong><strong>统计字符串含有的单词数</strong></p>
<p align="left">调用: mix
str_word_count(str $str,[])</p>
<p align="left">输入: 目标字符串 输出: 统计处的数量</p>
<p align="left"><strong>69.strlen(): </strong><strong>统计字符串长度</strong><strong>int strlen(str $str)</strong></p>
<p align="left">输入: 目标字符串 输出:整型长度</p>
<p align="left"><strong>70.count_chars(): </strong><strong>统计字符串中所有字母出现次数</strong><strong>(0..255) </strong><strong>调用</strong><strong>: mixed count_chars ( string $string [, int $mode ] )</strong></p>
<p align="left">字符串编码:</p>
<p align="left"><strong>71.md5(): </strong><strong>字符串</strong><strong>md5</strong><strong>编码</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$str =
"Hello";</p>
<p align="left">echo md5($str);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">数组函数</p>
<p align="left">数组创建:</p>
<p align="left"><strong>72.array(): </strong><strong>生成一个数组</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$a=array("Dog","Cat","Horse");</p>
<p align="left">print_r($a);</p>
</td>
</tr>
</tbody>
</table>
<p align="left"><br>
数组值或,键=>值一个数组型变量</p>
<p align="left"><strong>73.array_combine(): </strong><strong>生成一个数组</strong><strong>,</strong><strong>用一个数组的值</strong><strong>作为键名</strong><strong>,</strong><strong>另一个数组值作为值</strong></p>
<p align="left">
$a1=array("a","b","c","d");<br>
$a2=array("Cat","Dog","Horse","Cow");<br>
print_r(array_combine($a1,$a2));<br>
$a1为提供键,$a2提供值合成后的数组</p>
<p align="left"><strong>74.range(): </strong><strong>创建并返回一个包含指定范围的元素的数组。</strong></p>
<p align="left"> $number =
range(0,50,10);<br>
print_r ($number);<br>
输入: 0是最小值,50是最大值,10是步长 输出: 合成后的数组</p>
<p align="left"><strong>75.compact(): </strong><strong>创建一个由参数所带变量组成的数组</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
<p align="left">5</p>
<p align="left">6</p>
</td>
<td width="405">
<p align="left">$firstname
= "Peter";</p>
<p align="left">$lastname
= "Griffin";</p>
<p align="left">$age =
"38";</p>
<p align="left">$result =
compact("firstname", "lastname",</p>
<p align="left">"age");</p>
<p align="left">print_r($result);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">变量或数组</p>
<p align="left">返回由变量名为键,变量值为值的数组,变量也可以为多维数组.会递归处理 76.array_fill(): 用给定的填充(值生成)数组</p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$a=array_fill(2,3,"Dog");</p>
<p align="left">print_r($a);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">2是键,3是填充的数量,'Dog'为填充内容返回完成的数组</p>
<p align="left">数组合并和拆分: </p>
<p align="left"><strong>77.array_chunk(): </strong><strong>把一个数组分割为新的数组块</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$a=array("a"=>"Cat","b"=>"Dog","c"=>"Horse","d"=>"Cow");</p>
<p align="left">print_r(array_chunk($a,2));</p>
</td>
</tr>
</tbody>
</table>
<p align="left">一个数组分割后的多维数组,规定每个新数组包含2个元素</p>
<p align="left"><strong>78.array_merge(): </strong><strong>把两个或多个数组合并为一个数组。</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
</td>
<td width="405">
<p align="left">$a1=array("a"=>"Horse","b"=>"Dog");</p>
<p align="left">$a2=array("c"=>"Cow","b"=>"Cat");</p>
<p align="left">print_r(array_merge($a1,$a2));</p>
</td>
</tr>
</tbody>
</table>
<p align="left">输入: 两个数组 输出: 返回完成后的数组</p>
<p align="left"><strong>79.array_slice(): </strong><strong>在数组中根据条件取出一段值,并返回。</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$a=array(0=>"Dog",1=>"Cat",2=>"Horse",3=>"Bird");</p>
<p align="left">print_r(array_slice($a,1,2));</p>
</td>
</tr>
</tbody>
</table>
<p align="left">输入: 一个数组 输出: 1为从'Cat'开始,2为返回两个元素</p>
<p align="left">数组比较:</p>
<p align="left"><strong>80.array_diff(): </strong><strong>返回两个数组的差集数组</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
</td>
<td width="405">
<p align="left">$a1=array(0=>"Cat",1=>"Dog",2=>"Horse");</p>
<p align="left">$a2=array(3=>"Horse",4=>"Dog",5=>"Fish");</p>
<p align="left"> print_r(array_diff($a1,$a2));
//返回'Cat'</p>
</td>
</tr>
</tbody>
</table>
<p align="left">输入: 两个或多个数组 输出: $a1与$a2的不同之处</p>
<p align="left"><strong>81.array_intersect(): </strong><strong>返回两个或多个数组的交集数组</strong><strong>输出</strong><strong>: </strong><strong>返回</strong><strong>'Dog'</strong><strong>和</strong><strong>'Horse',$a1</strong><strong>与</strong><strong>$a2</strong><strong>的相同之处</strong></p>
<p align="left">数组查找替换: </p>
<p align="left"><strong>82.array_search(): </strong><strong>在数组中查找一个值,返回一个键,没有返回返回假</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$a=array("a"=>"Dog","b"=>"Cat","c"=>"Horse");</p>
<p align="left">echo array_search("Dog",$a);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">输入: 一个数组 输出: 成功返回键名,失败返回false</p>
<p align="left"><strong>83.array_splice(): </strong><strong>把数组中一部分删除用其他值替代</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
</td>
<td width="405">
<p align="left">$a1=array(0=>"Dog",1=>"Cat",2=>"Horse",3=>"Bird");</p>
<p align="left">$a2=array(0=>"Tiger",1=>"Lion");</p>
<p align="left">array_splice($a1,0,2,$a2);</p>
<p align="left">print_r($a1);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">输入: 一个或多个数组 输出: $a1被移除的部分由$a2补全</p>
<p align="left"><strong>84.array_sum(): </strong><strong>返回数组中所有值的总和</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$a=array(0=>"5",1=>"15",2=>"25");</p>
<p align="left">echo array_sum($a);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">输入: 一个数组 输出: 返回和</p>
<p align="left"><strong>85.in_array(): </strong><strong>在数组中搜索给定的值</strong><strong>,</strong><strong>区分大小写</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
<p align="left">5</p>
<p align="left">6</p>
<p align="left">7</p>
</td>
<td width="405">
<p align="left">$people =
array("Peter", "Joe", "Glenn",
"Cleveland");</p>
<p align="left">if (in_array("Glenn",$people)
{</p>
<p align="left">echo "Match
found";</p>
<p align="left">}</p>
<p align="left">else{</p>
<p align="left">echo "Match
not found";</p>
<p align="left">}</p>
</td>
</tr>
</tbody>
</table>
<p align="left">输入: 需要搜索的值|数组 输出: true/false</p>
<p align="left"><strong>86.array_key_exists(): </strong><strong>判断某个数组中是否存在指定的</strong><strong> key</strong></p>
<p align="left">输入: 需要搜索的键名|数组</p>
<p align="left">数组指针操作:</p>
<p align="left"><strong>87.key(): </strong><strong>返回数组内部指针当前指向元素的键名</strong><strong> </strong> </p>
<p align="left"><strong>88.current(): </strong><strong>返回数组中的当前元素</strong><strong>(</strong><strong>单元</strong><strong>). </strong><strong> </strong></p>
<p align="left"><strong>89.next(): </strong><strong>把指向当前元素的指针移动到下一个元素的位置</strong><strong>,</strong><strong>并返回当前元素的值</strong><strong> </strong></p>
<p align="left"><strong>90.prev(): </strong><strong>把指向当前元素的指针移动到上一个元素的位置</strong><strong>,</strong><strong>并返回当前元素的值</strong><strong> </strong></p>
<p align="left"><strong>91.end(): </strong><strong>将数组内部指针指向最后一个元素,并返回该元素的值</strong><strong>(</strong><strong>如果成功</strong><strong>) </strong><strong> </strong></p>
<p align="left"><strong>92.reset(): </strong><strong>把数组的内部指针指向第一个元素,并返回这个元素的值</strong><strong> </strong></p>
<p align="left"><strong>93.list(): </strong><strong>用数组中的元素为一组变量赋值</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$my_array=array("Dog","Cat","Horse");</p>
<p align="left">list($a,
$b, $c) = $my_array;</p>
</td>
</tr>
</tbody>
</table>
<p align="left"><br>
输入: $a, $b, $c为需要赋值的变量 输出: 变量分别匹配数组中的值</p>
<p align="left"><strong>94.array_shift(): </strong><strong>删除数组中的第一个元素,并返回被删除元素的值</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
</td>
<td width="405">
<p align="left">$a=array("a"=>"Dog","b"=>"Cat","c"=>"Horse");</p>
<p align="left">echo array_shift($a);</p>
<p align="left">print_r
($a);</p>
</td>
</tr>
</tbody>
</table>
<p align="left"><strong>95.array_unshift(): </strong><strong>在数组开头插入一个或多个元素</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
</td>
<td width="405">
<p align="left">$a=array("a"=>"Cat","b"=>"Dog");</p>
<p align="left">array_unshift($a,"Horse");</p>
<p align="left">print_r($a);</p>
</td>
</tr>
</tbody>
</table>
<p align="left"><strong>96.array_push(): </strong><strong>向数组最后压入一个或多个元素</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
</td>
<td width="405">
<p align="left">$a=array("Dog","Cat");</p>
<p align="left">array_push($a,"Horse","Bird");</p>
<p align="left">print_r($a);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">输入: 目标数组|需要压入的值 返回值: 返回新的数组</p>
<p align="left"><strong>97.array_pop(): </strong><strong>取得(删除)数组中的最后一个元素</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
</td>
<td width="405">
<p align="left">$a=array("Dog","Cat","Horse");</p>
<p align="left">array_pop($a);</p>
<p align="left">print_r($a);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">输入: $a为目标数组 输出: 返回数组剩余元素</p>
<p align="left">数组键值操作: </p>
<p align="left"><strong>98.shuffle(): </strong><strong>将数组打乱</strong><strong>,</strong><strong>保留键名</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
</td>
<td width="405">
<p align="left">$my_array
= array("a" => "Dog", "b" =>
"Cat");</p>
<p align="left">shuffle($my_array);</p>
<p align="left">print_r($my_array);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">输入: 一个或多个数组 输出: 顺序打乱后的数组</p>
<p align="left"><strong>99.count(): </strong><strong>计算数组中的单元数目或对象中的属性个数</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
</td>
<td width="405">
<p align="left">$people =
array("Peter", "Joe", "Glenn",</p>
<p align="left">"Cleveland");</p>
<p align="left">$result =
count($people);</p>
<p align="left">echo $result;</p>
</td>
</tr>
</tbody>
</table>
<p align="left"><br>
输入: 数组 输出: 输出元素个数</p>
<p align="left"><strong>100.array_flip(): </strong><strong>返回一个键值反转后的数组</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$a=array(0=>"Dog",1=>"Cat",2=>"Horse");</p>
<p align="left">print_r(array_flip($a));</p>
</td>
</tr>
</tbody>
</table>
<p align="left"><br>
输出: 返回完成后的数组
101.array_keys(): 返回数组所有的键,组成一个数组</p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$a=array("a"=>"Horse","b"=>"Cat","c"=>"Dog");</p>
<p align="left">print_r(array_keys($a));</p>
</td>
</tr>
</tbody>
</table>
<p align="left">输出: 返回由键名组成的数组</p>
<p align="left"><strong>102.array_values(): </strong><strong>返回数组中所有值,组成一个数组</strong></p>
<p align="left">输出: 返回由键值组成的数组</p>
<p align="left"><strong>103.array_reverse(): </strong><strong>返回一个元素顺序相反的数组</strong><strong>元素顺序相反的一个数组,键名和键值依然匹配</strong></p>
<p align="left"><strong>104.array_count_values(): </strong><strong>统计数组中所有的值出现的次数</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$a=array("Cat","Dog","Horse","Dog");</p>
<p align="left">print_r(array_count_values($a));</p>
</td>
</tr>
</tbody>
</table>
<p align="left">输出: 返回数组原键值为新键名,次数为新键值</p>
<p align="left"><strong>105.array_rand(): </strong><strong>从数组中随机抽取一个或多个元素</strong><strong>,</strong><strong>注意是键名</strong><strong>!!!</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$a=array("a"=>"Dog","b"=>"Cat","c"=>"Horse");</p>
<p align="left">print_r(array_rand($a,1));</p>
</td>
</tr>
</tbody>
</table>
<p align="left">$a为目标数组, 1为抽取第几个元素的键名返回第1个元素的键名b</p>
<p align="left"><strong>106.each(): </strong><strong>返回数组中当前的键/值对并将数组指针向前移动一步</strong><strong>调用</strong><strong>array each (
array &$array )</strong></p>
<p align="left">在执行 each() 之后,数组指针将停留在数组中的下一个单元或者当碰到数组结尾时停留在最后一个单元。如果要再用 each 遍历数组,必须使用 reset()。</p>
<p align="left">返回值: 数组中当前指针位置的键/值对并向前移动数组指针。键值对被返回为四个单元的数组,键名为0,1,key和 value。单元 0 和 key 包含有数组单元的键名,1 和 value 包含有数据。 如果内部指针越过了数组的末端,则 each() 返回 FALSE。</p>
<p align="left"><strong>107.array_unique(): </strong><strong>删除重复值,返回剩余数组</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$a=array("a"=>"Cat","b"=>"Dog","c"=>"Cat");</p>
<p align="left">print_r(array_unique($a));</p>
</td>
</tr>
</tbody>
</table>
<p align="left">输入: 数组 输入: 返回无重复值数组,键名不变</p>
<p align="left">数组排序: </p>
<p align="left"><strong>108.sort(): </strong><strong>按升序对给定数组的值排序</strong><strong>,</strong><strong>不保留键名</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
</td>
<td width="405">
<p align="left">$my_array
= array("a" => "Dog", "b" =>
"Cat",</p>
<p align="left">"c"
=> "Horse");</p>
<p align="left">sort($my_array);</p>
<p align="left">print_r($my_array);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">输出: true/false 109.rsort(): 对数组逆向排序,不保留键名 110.asort(): 对数组排序,保持索引关系 111.arsort(): 对数组逆向排序,保持索引关 112.ksort(): 系按键名对数组排序 113.krsort(): 将数组按照键逆向排序 114.natsort(): 用自然顺序算法对数组中的元素排序
115.natcasesort(): 自然排序,不区分大小写 </p>
<p align="left">文件系统函数</p>
<p align="left"><strong>116.fopen(): </strong><strong>打开文件或者</strong><strong> URL</strong></p>
<p align="left"> $handle =
fopen("ftp://user:password@example.com/somefile.txt", "w");<br>
调用: resource fopen ( string filename, string mode [, bool
use_include_path [, resource zcontext]] )</p>
<p align="left">返回值: 如果打开失败,本函数返回 FALSE</p>
<p align="left"><strong>117.fclose(): </strong><strong>关闭一个已打开的文件指针</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
</td>
<td width="405">
<p align="left">$handle =
fopen('somefile.txt', 'r');</p>
<p align="left">fclose($handle);</p>
<p align="left">bool
fclose(resource handle)</p>
</td>
</tr>
</tbody>
</table>
<p align="left"><br>
输出: 如果成功则返回 TRUE,失败则返回 FALSE</p>
<p align="left">文件属性</p>
<p align="left"><strong>118.file_exists(): </strong><strong>检查文件或目录是否存在</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
<p align="left">5</p>
<p align="left">6</p>
</td>
<td width="405">
<p align="left">$filename
= '/path/to/foo.txt';</p>
<p align="left">if (file_exists($filename))
{</p>
<p align="left">echo "exists";</p>
<p align="left">} else {</p>
<p align="left">echo "does
not exist";</p>
<p align="left">}</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: bool
file_exists ( string filename ) 输入: 指定的文件或目录 输出: 存在则返回 TRUE,否则返回 FALSE</p>
<p align="left"><strong>119.filesize(): </strong><strong>取得文件大小</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$filename
= 'somefile.txt';</p>
<p align="left">echo $filename
. ': ' . filesize($filename) .'bytes';</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: int filesize (
string $filename )</p>
<p align="left">输出: 返回文件大小的字节数,如果出错返回 FALSE 并生成一条 E_WARNING 级的错误</p>
<p align="left"><strong>120.is_readable(): </strong><strong>判断给定文件是否可读</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
<p align="left">5</p>
<p align="left">6</p>
</td>
<td width="405">
<p align="left">$filename
= 'test.txt';</p>
<p align="left">if (is_readable($filename))
{</p>
<p align="left">echo '可读';</p>
<p align="left">} else {</p>
<p align="left">echo '不可读';</p>
<p align="left">}</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: bool
is_readable ( string $filename ) 输出: 如果由 filename指定的文件或目录存在并且可读则返回 TRUE</p>
<p align="left"><strong>121.is_writable(): </strong><strong>判断给定文件是否可写</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
<p align="left">5</p>
<p align="left">6</p>
</td>
<td width="405">
<p align="left">$filename
= 'test.txt';</p>
<p align="left">if (is_writable($filename))
{</p>
<p align="left">echo '可写';</p>
<p align="left">} else {</p>
<p align="left">echo '不可写';</p>
<p align="left">}</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: bool
is_writable ( string $filename ) filename 参数 可以是一个允许进行是否可写检查的目录名</p>
<p align="left">输出: 如果文件存在并且可写则返回 TRUE。</p>
<p align="left"><strong>122.is_executable(): </strong><strong>判断给定文件是否可执行</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
<p align="left">5</p>
<p align="left">6</p>
</td>
<td width="405">
<p align="left">$file =
'setup.exe';</p>
<p align="left">if (is_executable($file))
{</p>
<p align="left">echo '可执行';</p>
<p align="left">} else {</p>
<p align="left">echo '不可执行';</p>
<p align="left">}</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: bool
is_executable ( string $filename ) 输出: 如果文件存在且可执行则返回 TRUE</p>
<p align="left"><strong>123.filectime(): </strong><strong>获取文件的创建时间</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$filename
= 'somefile.txt';</p>
<p align="left">echo filectime($filename);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: int filectime
( string $filename ) 输出: 时间以 Unix 时间戳的方式返回,如果出错则返回FALSE</p>
<p align="left"><strong>124.filemtime(): </strong><strong>获取文件的修改时间</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$filename
= 'somefile.txt';</p>
<p align="left">echo filemtime($filename);</p>
</td>
</tr>
</tbody>
</table>
<p align="left"> int filemtime (
string $filename )<br>
输出: 返回文件上次被修改的时间,出错时返回 FALSE。时间以 Unix时间戳的方式返回</p>
<p align="left"><strong>125.fileatime(): </strong><strong>获取文件的上次访问时间</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$filename
= 'somefile.txt';</p>
<p align="left">echo fileatime($filename);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: int fileatime
(string $filename)</p>
<p align="left">输出: 返回文件上次被访问的时间, 如果出错则返回FALSE. 时间以Unix时间戳的方式返回.</p>
<p align="left"><strong>126.stat(): </strong><strong>获取文件大部分属性值</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$filename
= 'somefile.txt';</p>
<p align="left">var_dump(fileatime($filename));</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: array stat
(string $filename 输出: 返回由 filename 指定的文件的统计信息</p>
<p align="left">文件操作</p>
<p align="left"><strong>127.fwrite(): </strong><strong>写入文件</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
<p align="left">5</p>
</td>
<td width="405">
<p align="left">$filename
= 'test.txt';</p>
<p align="left">$somecontent
= "添加这些文字到文件\n";</p>
<p align="left">$handle =
fopen($filename, 'a');</p>
<p align="left">fwrite($handle,
$somecontent);</p>
<p align="left">fclose($handle);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: int fwrite (
resource handle, string string [, int length] )</p>
<p align="left">输出: 把 string 的内容写入 文件指针 handle 处。如果指定了 length,当写入了length个字节或者写完了string以后,写入就会停止, 视乎先碰到哪种情况</p>
<p align="left"><strong>128.fputs(): </strong><strong>同上 </strong><strong> </strong></p>
<p align="left"><strong>129.fread(): </strong><strong>读取文件</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
</td>
<td width="405">
<p align="left">$filename
= "/usr/local/something.txt";</p>
<p align="left">$handle =
fopen($filename, "r");</p>
<p align="left">$contents
= fread($handle, filesize($filename));</p>
<p align="left"> fclose($handle);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: string fread (
int handle, int length ) 从文件指针handle,读取最多 length 个字节</p>
<p align="left"><strong>130.feof(): </strong><strong>检测文件指针是否到了文件结束的位置</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
</td>
<td width="405">
<p align="left">$file =
@fopen("no_such_file", "r");</p>
<p align="left">while (!feof($file))
{</p>
<p align="left">}</p>
<p align="left">fclose($file);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: bool feof (
resource handle ) 输出: 如果文件指针到了 EOF 或者出错时则返回TRUE,否则返回一个错误(包括 socket 超时),其它情况则返回 FALSE</p>
<p align="left"><strong>131.fgets(): </strong><strong>从文件指针中读取一行</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
<p align="left">5</p>
<p align="left">6</p>
<p align="left">7</p>
<p align="left">8</p>
</td>
<td width="405">
<p align="left">$handle =
@fopen("/tmp/inputfile.txt", "r");</p>
<p align="left">if ($handle)
{</p>
<p align="left">while (!feof($handle))
{</p>
<p align="left">$buffer =
fgets($handle, 4096);</p>
<p align="left">echo $buffer;</p>
<p align="left">}</p>
<p align="left">fclose($handle);</p>
<p align="left">}</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: string fgets (
int handle [, int length] ) 输出: 从handle指向的文件中读取一行并返回长度最多为length-1字节的字符串.碰到换行符(包括在返回值中)、EOF 或者已经读取了length -1字节后停止(看先碰到那一种情况). 如果没有指定 length,则默认为1K, 或者说 1024 字节.</p>
<p align="left"><strong>132.fgetc(): </strong><strong>从文件指针中读取字符</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
<p align="left">5</p>
<p align="left">6</p>
<p align="left">7</p>
</td>
<td width="405">
<p align="left">$fp =
fopen('somefile.txt', 'r');</p>
<p align="left">if (!$fp)
{</p>
<p align="left">echo 'Could
not open file somefile.txt';</p>
<p align="left">}</p>
<p align="left">while (false
!== ($char = fgetc($fp))) {</p>
<p align="left">echo "$char\n";</p>
<p align="left">}</p>
</td>
</tr>
</tbody>
</table>
<p align="left">输入: string fgetc (
resource $handle ) 输出: 返回一个包含有一个字符的字符串,该字符从 handle指向的文件中得到. 碰到 EOF 则返回 FALSE.</p>
<p align="left"><strong>133.file(): </strong><strong>把整个文件读入一个数组中</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
<p align="left">5</p>
<p align="left">6</p>
<p align="left">7</p>
<p align="left">8</p>
<p align="left">9</p>
<p align="left">10</p>
</td>
<td width="399">
<p align="left">$lines =
file('http://www.example.com/');</p>
<p align="left">// 在数组中循环,显示 HTML 的源文件并加上行号。</p>
<p align="left"> </p>
<p align="left"> foreach
($lines as $line_num => $line) {</p>
<p align="left"> echo
"Line #<b>{$line_num}</b> : " .</p>
<p align="left"> htmlspecialchars($line)
. "<br />\n";</p>
<p align="left"> }</p>
<p align="left">// 另一个例子将 web 页面读入字符串。参见 file_get_contents()。</p>
<p align="left"> </p>
<p align="left"> $html
= implode('', file('http://www.example.com/'));</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: array file (
string $filename [, int $use_include_path [, resource $context ]] )</p>
<p align="left">输出: 数组中的每个单元都是文件中相应的一行,包括换行符在内。如果失败 file() 返回 FALSE</p>
<p align="left"><strong>134.readfile(): </strong><strong>输出一个文件 </strong><strong>调用</strong><strong>: int readfile (
string $filename [, bool $use_include_path [, resource $context ]] )</strong></p>
<p align="left">输出: 读入一个文件并写入到输出缓冲。返回从文件中读入的字节数。如果出错返回 FALSE</p>
<p align="left"><strong>135.file_get_contents(): </strong><strong>将整个文件读入一个字符串</strong></p>
<p align="left"> echo
file_get_contents('http://www.baidu.com');<br>
调用: string file_get_contents ( string $filename [, bool
$use_include_path [, resource $context [, int $offset [, int $maxlen ]]]] ) <strong>136.file_put_contents():</strong><strong>将一个字符串写入文件</strong></p>
<p align="left">
file_put_contents('1.txt','aa');<br>
调用: int file_put_contents ( string $filename , string $data
[, int $flags [, resource $context ]] )</p>
<p align="left">输出: 该函数将返回写入到文件内数据的字节数</p>
<p align="left"><strong>137.ftell(): </strong><strong>返回文件指针读</strong><strong>/</strong><strong>写的位置</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
<p align="left">5</p>
</td>
<td width="405">
<p align="left">$fp=fopen('tx.txt','r');</p>
<p align="left">fseek($fp,10);</p>
<p align="left">echo ftell($fp);</p>
<p align="left">fread($fp,4);</p>
<p align="left">echo ftell($fp);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: int ftell (
resource $handle ) 输出: 返回由 handle 指定的文件指针的位置,也就是文件流中的偏移量</p>
<p align="left"><strong>138.fseek(): </strong><strong>在文件指针中定位</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
<p align="left">5</p>
</td>
<td width="405">
<p align="left">$fp=fopen('tx.txt','r');</p>
<p align="left">fseek($fp,10);</p>
<p align="left">echo ftell($fp);</p>
<p align="left">fread($fp,4);</p>
<p align="left">echo ftell($fp);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: int fseek (
resource $handle , int $offset [, int $whence ] ) 输出: 成功则返回 0;否则返回 -1</p>
<p align="left"><strong>139.rewind(): </strong><strong>倒回文件指针的位置</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
<p align="left">5</p>
<p align="left">6</p>
</td>
<td width="405">
<p align="left">$fp=fopen('tx.txt','r');</p>
<p align="left">fseek($fp,3);</p>
<p align="left">echo ftell($fp);</p>
<p align="left">fread($fp,4);</p>
<p align="left">rewind($fp);</p>
<p align="left">echo ftell($fp);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: bool rewind (
resource $handle ) 返回值: 如果成功则返回 TRUE,失败则返回 FALSE</p>
<p align="left"><strong>140.flock(): </strong><strong>轻便的执行文件锁定</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
<p align="left">5</p>
<p align="left">6</p>
</td>
<td width="405">
<p align="left">$fp=fopen('tx.txt','r');</p>
<p align="left">flock($fp,
LOCK_SH);//共享锁</p>
<p align="left">//flock($fp,
LOCK_EX);//独立锁,写文件时用它打开</p>
<p align="left">//flock($fp,
LOCK_NB);//附加锁</p>
<p align="left">flock($fp,
LOCK_UN);//释放锁</p>
<p align="left">fclose($fp);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: bool flock (
int $handle , int $operation [, int &$wouldblock ] ) 输出: 如果成功则返回 TRUE,失败则返回 FALSE</p>
<p align="left"><strong>目录</strong></p>
<p align="left"><strong>141.basename(): </strong><strong>返回路径中的文件名部分</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
</td>
<td width="405">
<p align="left">path =
"/home/httpd/html/index.php";</p>
<p align="left">$file =
basename($path);</p>
<p align="left">$file =
basename($path,".php");</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: string
basename ( string $path [, string $suffix ]) 输出: 给出一个包含有指向一个文件的全路径的字符串,本函数返回基本的文件名。如果文件名是以 suffix 结 束的,那这一部分也会被去掉</p>
<p align="left"><strong>142.dirname(): </strong><strong>返回路径中的目录部分</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$path =
"/etc/passwd";</p>
<p align="left">$file =
dirname($path);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: string dirname
( string $path ) 输出: 给出一个包含有指向一个文件的全路径的字符串,本函数返回去掉文件名后的目录名</p>
<p align="left"><strong>143.pathinfo(): </strong><strong>返回文件路径的信息</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
</td>
<td width="405">
<p align="left">echo '<pre>';</p>
<p align="left">print_r(pathinfo("/www/htdocs/index.html"));</p>
<p align="left">echo '</pre>';</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: mixed pathinfo
( string $path [, int $options ] ) 返回一个关联数组包含有 path 的信息</p>
<p align="left"><strong>144.opendir(): </strong><strong>打开目录句柄</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
</td>
<td width="405">
<p align="left">$fp=opendir('E:/xampp/htdocs/php/study/19');</p>
<p align="left">echo readdir($fp);</p>
<p align="left">closedir($fp);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: resource
opendir ( string $path [, resource $context ] ) 返回值: 如果成功则返回目录句柄的 resource,失败则返回FALSE</p>
<p align="left"><strong>145.readdir(): </strong><strong>从目录句柄中读取条目</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
</td>
<td width="405">
<p align="left">$fp=opendir('E:/xampp/htdocs/php/study/19');</p>
<p align="left">echo readdir($fp);</p>
<p align="left">closedir($fp);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: string readdir
( resource $dir_handle ) 返回值: 返回目录中下一个文件的文件名。文件名以在文件系统中的排序返回</p>
<p align="left"><strong>146.closedir(): </strong><strong>关闭目录句柄</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
</td>
<td width="405">
<p align="left">$fp=opendir('E:/xampp/htdocs/php/study/19');</p>
<p align="left">echo readdir($fp);</p>
<p align="left">closedir($fp);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: void closedir
( resource $dir_handle ) 关闭由 dir_handle 指定的目录流。流必须之前被opendir() 所打开 147.rewinddir()
: 倒回目录句柄</p>
<p align="left"> </p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
<p align="left">5</p>
<p align="left">6</p>
<p align="left">7</p>
</td>
<td width="405">
<p align="left">$fp=opendir('E:/xampp/htdocs/php/study/19');</p>
<p align="left">echo readdir($fp).'<br
/>';</p>
<p align="left">echo readdir($fp).'<br
/>';</p>
<p align="left">echo readdir($fp).'<br
/>';</p>
<p align="left">rewinddir($fp);</p>
<p align="left">echo readdir($fp).'<br
/>';</p>
<p align="left">closedir($fp);</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: void rewinddir
( resource $dir_handle ) 输出: 将 dir_handle 指定的目录流重置到目录的开头 148.mkdir(): 新建目录</p>
<p align="left"> mkdir('123');<br>
调用: bool mkdir ( string $pathname [, int $mode [, bool
$recursive [, resource $context ]]] ) 输出: 尝试新建一个由 pathname 指定的目录</p>
<p align="left"><strong>149.rmdir(): </strong><strong>删除目录</strong></p>
<p align="left"> rmdir('123');<br>
调用: bool rmdir ( string $dirname ) 输出: 尝试删除 dirname 所指定的目录。目录必须是空的,而且要有相应的权限。如果成功则返回TRUE,失败则返回 FALSE</p>
<p align="left"><strong>150.unlink(): </strong><strong>删除文件</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">unlink('123/1.txt');</p>
<p align="left">rmdir('123');</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: bool unlink (
string $filename ) 输出: 删除 filename 。和 Unix C 的 unlink() 函数相似。如果成功则返回 TRUE,失败则返回 FALSE</p>
<p align="left"><strong>151.copy(): </strong><strong>拷贝文件</strong></p>
<p align="left">
copy('index.php','index.php.bak');<br>
调用: bool copy ( string $source , string $dest ) 输出: 将文件从 source 拷贝到 dest. 如果成功则返回TRUE,失败则返回 FALSE</p>
<p align="left"><strong>152.rename(): </strong><strong>重命名一个文件或目录</strong></p>
<p align="left">
rename('tx.txt','txt.txt');<br>
调用: bool rename ( string $oldname , string $newname [,
resource $context ] ) 输出: 如果成功则返回 TRUE,失败则返回 FALSE</p>
<p align="left"><strong>文件的上传与下载</strong></p>
<p align="left"><strong>153.is_uploaded_file():</strong><strong>判断文件是否是通过</strong><strong> HTTP POST</strong><strong>上传的</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
<p align="left">5</p>
<p align="left">6</p>
<p align="left">7</p>
<p align="left">8</p>
<p align="left">9</p>
<p align="left">10</p>
</td>
<td width="399">
<p align="left">if(is_uploaded_file($_FILES['bus']['tmp_name'])){</p>
<p align="left">if(
move_uploaded_file($_FILES['bus']['tmp_name'],</p>
<p align="left">$NewPath)
){</p>
<p align="left">echo '上传成功<br /><img
src="'.$NewPath.'">';</p>
<p align="left">}else{</p>
<p align="left">exit('失败');</p>
<p align="left">}</p>
<p align="left">}else{</p>
<p align="left">exit('不是上传文件');</p>
<p align="left">}</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: bool
is_uploaded_file ( string $filename ) </p>
<p align="left"><strong>154.move_uploaded_file(): </strong><strong>将上传的文件移动到新位置</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
<p align="left">5</p>
<p align="left">6</p>
<p align="left">7</p>
<p align="left">8</p>
<p align="left">9</p>
<p align="left">10</p>
</td>
<td width="399">
<p align="left">if(is_uploaded_file($_FILES['bus']['tmp_name'])){</p>
<p align="left">if(
move_uploaded_file($_FILES['bus']['tmp_name'],</p>
<p align="left">$NewPath)
){</p>
<p align="left">echo '上传成功<br /><img
src="'.$NewPath.'">';</p>
<p align="left">}else{</p>
<p align="left">exit('失败');</p>
<p align="left">}</p>
<p align="left">}else{</p>
<p align="left">exit('不是上传文件');</p>
<p align="left">}</p>
</td>
</tr>
</tbody>
</table>
<p align="left">调用: bool
move_uploaded_file ( string $filename , string</p>
<p align="left">时间函数</p>
<p align="left"><strong>155.time(): </strong><strong>返回当前的</strong><strong> Unix </strong><strong>时间戳</strong><strong>time(); </strong><strong>调用</strong><strong>: int time ( void ) </strong><strong>输出</strong><strong>: </strong><strong>返回自从</strong><strong> Unix </strong><strong>纪元(格林威治时间</strong><strong> 1970 </strong><strong>年</strong><strong> 1 </strong><strong>月</strong><strong> 1 </strong><strong>日</strong><strong> 00:00:00</strong><strong>)到当前时间的秒数</strong></p>
<p align="left"><strong>156.mktime(): </strong><strong>取得一个日期的</strong><strong> Unix </strong><strong>时间戳</strong></p>
<p align="left"> mktime(0, 0, 0, 4,
25, 2012);<br>
调用: int mktime ([ int $hour [, int $minute [, int $second
[, int $month [, int $day [, int $year [, int $is_dst ]]]]]]] ) 156.date(): 格式化一个本地时间/日期</p>
<p align="left">date('Y年m月d日 H:i:s');<br>
调用: string date ( string $format [, int $timestamp ] )</p>
<p align="left">输出: 2016年09月10日 20:45:54</p>
<p align="left"><strong>157.checkdate(): </strong><strong>验证一个格里高里日期</strong><strong>调用</strong><strong>: bool checkdate
( int $month , int $day , int $year) </strong><strong>输出</strong><strong>: </strong><strong>如果给出的日期有效则返回</strong><strong> TRUE</strong><strong>,否则返回</strong><strong> FALSE</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
<p align="left">5</p>
</td>
<td width="405">
<p align="left">if(checkdate(6,31,2012)){</p>
<p align="left">echo '成立';</p>
<p align="left">}else{</p>
<p align="left">echo '不成立';</p>
<p align="left">}</p>
</td>
</tr>
</tbody>
</table>
<p align="left"><strong>158.date_default_timezone_set(): </strong><strong>设定用于一个脚本中所有日期时间函数的默认时区</strong></p>
<p align="left">
date_default_timezone_set('PRC');<br>
调用: bool date_default_timezone_set ( string
$timezone_identifier)</p>
<p align="left">返回值: 如果 timezone_identifier 参数无效则返回 FALSE,否则返回 TRUE。</p>
<p align="left"><strong>159.getdate(): </strong><strong>取得日期/时间信息</strong><strong>调用</strong><strong>: array getdate
([ int $timestamp ] )</strong></p>
<p align="left">输出: 返回一个根据timestamp得出的包含有日期信息的关联数组。如果没有给出时间戳则认为是当前本地时间</p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
</td>
<td width="405">
<p align="left">$t=getdate();</p>
<p align="left">var_dump($t);</p>
</td>
</tr>
</tbody>
</table>
<p align="left"><strong>160.strtotime(): </strong><strong>将任何英文文本的日期时间描述解析为</strong><strong> Unix </strong><strong>时间戳</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
<p align="left">5</p>
<p align="left">6</p>
<p align="left">7</p>
<p align="left">8</p>
</td>
<td width="405">
<p align="left">echo strtotime("now");</p>
<p align="left">int
strtotime ( string $time [, int $now ] ) </p>
<p align="left">echo strtotime("10
September 2000");</p>
<p align="left">echo strtotime("+1
day");</p>
<p align="left">echo strtotime("+1
week");</p>
<p align="left">echo strtotime("+1
week 2 days 4 hours 2 seconds");</p>
<p align="left">echo strtotime("next
Thursday");</p>
<p align="left">echo strtotime("last
Monday");</p>
</td>
</tr>
</tbody>
</table>
<p align="left"><strong>161.microtime(): </strong><strong>返回当前</strong><strong> Unix </strong><strong>时间戳和微秒数</strong><strong>调用</strong><strong>: mixed
microtime ([ bool $get_as_float ] )</strong></p>
<table style="width: 426px" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p align="left">1</p>
<p align="left">2</p>
<p align="left">3</p>
<p align="left">4</p>
</td>
<td width="405">
<p align="left">$start=microtime(true);</p>
<p align="left">sleep(3);</p>
<p align="left">$stop=microtime(true);</p>
<p align="left">echo $stop-$start;</p>
</td>
</tr>
</tbody>
</table><br><br>
来源:https://www.cnblogs.com/xuesensen/p/11359221.html
頁:
[1]