<p>base类相关函数 要看的<br /> <br /> time<br /> time -- 返回当前的 Unix 时间戳<br /> 例子 1. time() 例子<br /> <!--p<br--> $nextWeek = time() + (7 * 24 * 60 * 60);<br /> // 7 days; 24 hours; 60 mins; 60secs<br /> echo 'Now: '. date('Y-m-d') .&quot;n&quot;;<br /> echo 'Next Week: '. date('Y-m-d', $nextWeek) .&quot;n&quot;;<br /> ?&gt; <br /> 上例的输出类似于:<br /> Now: 2005-03-30<br /> Next Week: 2005-04-07<br /> <br /> <br /> <br /> strcasecmp<br /> 例子 1. strcasecmp() example<br /> <!--p<br--> $var1 = &quot;Hello&quot;;<br /> $var2 = &quot;hello&quot;;<br /> if (strcasecmp($var1, $var2) == 0) {<br /> echo '$var1 is equal to $var2 in a case-insensitive string comparison';<br /> }<br /> ?&gt; <br /> <br /> max<br /> max -- 找出最大值<br /> 例子 1. 使用 max() 的例子<br /> <br /> <!--p<br--> echo max(1, 3, 5, 6, 7); // 7<br /> echo max(array(2, 4, 5)); // 5<br /> echo max(0, 'hello'); // 0<br /> echo max('hello', 0); // hello<br /> echo max(-1, 'hello'); // hello<br /> // 对多个数组,max 从左向右比较。<br /> // 因此在本例中:2 == 2,但 4 &lt; 5<br /> $val = max(array(2, 4, 8), array(2, 5, 7)); // array(2, 5, 7)<br /> // 如果同时给出数组和非数组作为参数,则总是将数组视为<br /> // 最大值返回<br /> $val = max('string', array(2, 5, 7), 42); // array(2, 5, 7)<br /> ?&gt; <br /> <br /> intval<br /> (PHP 3, PHP 4, PHP 5)<br /> intval -- 获取变量的整数值<br /> <br /> in_array<br /> in_array -- 检查数组中是否存在某个值<br /> 例子 1. in_array() 例子<br /> <!--p<br--> $os = array(&quot;Mac&quot;, &quot;NT&quot;, &quot;Irix&quot;, &quot;Linux&quot;);<br /> if (in_array(&quot;Irix&quot;, $os)) {<br /> echo &quot;Got Irix&quot;;<br /> }<br /> if (in_array(&quot;mac&quot;, $os)) {<br /> echo &quot;Got mac&quot;;<br /> }<br /> ?&gt; <br /> <br /> abs<br /> abs -- 绝对值<br /> 例子 1. abs() <br /> <!--p<br--> $abs = abs(-4.2); // $abs = 4.2; (double/float)<br /> $abs2 = abs(5); // $abs2 = 5; (integer)<br /> $abs3 = abs(-5); // $abs3 = 5; (integer)<br /> ?&gt; <br /> <br /> sprintf<br /> sprintf -- Return a formatted string<br /> <br /> is_dir<br /> is_dir -- 判断给定文件名是否是一个目录<br /> 例子 1. is_dir() 例子<br /> <!--r-->var_dump(is_dir('a_file.txt')) . &quot;n&quot;;<br /> var_dump(is_dir('bogus_dir/abc')) . &quot;n&quot;;<br /> var_dump(is_dir('..')); //one dir up<br /> ?&gt; <br /> 上例将输出:<br /> bool(false)<br /> bool(false)<br /> bool(true)<br /> <br /> <br /> <br /> mkdir<br /> mkdir -- 新建目录<br /> 说明<br /> bool mkdir ( string pathname [, int mode] )<br /> 尝试新建一个由 pathname 指定的目录。 <br /> 注意也许想用八进制数指定模式,也就是说该数应以零打头。模式也会被当前的 umask 修改,可以用 umask() 来改变。 <br /> 注: Mode 在 Windows 下被忽略。自 PHP 4.2.0 起成为可选项。 <br /> 默认的 mode 是 0777,意味着最大可能的访问权。有关 mode 的更多信息请阅读 chmod() 页面。 <br /> 例子 1. mkdir() 例子<br /> <!--p<br--> mkdir(&quot;/path/to/my/dir&quot;, 0700);<br /> ?&gt; <br /> <br /> implode<br /> implode -- Join array elements with a string<br /> 例子 1. implode() example<br /> <!--p<br--> $array = array('lastname', 'email', 'phone');<br /> $comma_separated = implode(&quot;,&quot;, $array);<br /> echo $comma_separated; // lastname,email,phone<br /> ?&gt; <br /> <br /> gmdate<br /> gmdate -- 格式化一个 GMT/UTC 日期/时间<br /> <br /> array_keys<br /> array_keys -- 返回数组中所有的键名<br /> 例子 1. array_keys() 例子<br /> <br /> <!--p<br--> $array = array(0 =&gt; 100, &quot;color&quot; =&gt; &quot;red&quot;);<br /> print_r(array_keys($array));<br /> $array = array(&quot;blue&quot;, &quot;red&quot;, &quot;green&quot;, &quot;blue&quot;, &quot;blue&quot;);<br /> print_r(array_keys($array, &quot;blue&quot;));<br /> $array = array(&quot;color&quot; =&gt; array(&quot;blue&quot;, &quot;red&quot;, &quot;green&quot;),<br /> &quot;size&quot; =&gt; array(&quot;small&quot;, &quot;medium&quot;, &quot;large&quot;));<br /> print_r(array_keys($array));<br /> ?&gt; <br /> <br /> array_values<br /> array_values -- 返回数组中所有的值<br /> 例子 1. array_values() 例子<br /> <!--p<br--> $array = array(&quot;size&quot; =&gt; &quot;XL&quot;, &quot;color&quot; =&gt; &quot;gold&quot;);<br /> print_r(array_values($array));<br /> ?&gt; <br /> <br /> serialize<br /> serialize -- 产生一个可存储的值的表示 <br /> 例子 1. serialize() 示例<br /> <br /> <!--p<br--> // $session_data 是包含了当前用户 session 信息的多维数组。<br /> // 我们使用 serialize() 在请求结束之前将其存储到数据库中。<br /> $conn = odbc_connect (&quot;webdb&quot;, &quot;php&quot;, &quot;chicken&quot;);<br /> $stmt = odbc_prepare ($conn,<br /> &quot;UPDATE sessions SET data = ? WHERE id = ?&quot;);<br /> $sqldata = array (serialize($session_data), $PHP_AUTH_USER);<br /> if (!odbc_execute ($stmt, &amp;$sqldata)) {<br /> $stmt = odbc_prepare($conn,<br /> &quot;INSERT INTO sessions (id, data) VALUES(?, ?)&quot;);<br /> if (!odbc_execute($stmt, &amp;$sqldata)) {<br /> /* 出错 */<br /> }<br /> }<br /> ?&gt; <br /> <br /> unserialize<br /> unserialize -- 从已存储的表示中创建 PHP 的值 <br /> unserialize_callback_func 示例<br /> <br /> <!--p<br--> $serialized_object='O:1:&quot;a&quot;:1:{s:5:&quot;value&quot;;s:3:&quot;100&quot;;}';<br /> // unserialize_callback_func 从 PHP 4.2.0 起可用<br /> ini_set('unserialize_callback_func','mycallback'); // 设置您的回调函数<br /> function mycallback($classname) {<br /> // 只需包含含有类定义的文件<br /> // $classname 指出需要的是哪一个类<br /> }<br /> ?&gt; <br /> <br /> base64_encode<br /> base64_encode -- 使用 MIME base64 对数据进行编码<br /> <!--p<br--> $str = 'This is an encoded string';<br /> echo base64_encode($str);<br /> ?&gt; <br /> <br /> base64_decode<br /> base64_decode -- 对使用 MIME base64 编码的数据进行解码<br /> <!--p<br--> $str = 'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==';<br /> echo base64_decode($str);<br /> ?&gt; <br /> <br /> ord<br /> ord -- Return ASCII value of character<br /> 例子 1. ord() example<br /> <!--p<br--> $str = &quot;n&quot;;<br /> if (ord($str) == 10) {<br /> echo &quot;The first character of $str is a line feed.n&quot;;<br /> }<br /> ?&gt; <br /> <br /> chr<br /> chr -- 返回指定的字符<br /> 例子 1. chr() 示例<br /> <!--p<br--> $str = &quot;The string ends in escape: &quot;;<br /> $str .= chr(27); /* 在 $str 后边增加换码符 */<br /> /* 通常这样更有用 */<br /> $str = sprintf(&quot;The string ends in escape: %c&quot;, 27);<br /> ?&gt; <br /> <br /> range<br /> range -- 建立一个包含指定范围单元的数组 <br /> 例子 1. range() 例子<br /> <!--p<br--> // array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)<br /> foreach (range(0, 12) as $number) {<br /> echo $number;<br /> }<br /> <br /> // The step parameter was introduced in 5.0.0<br /> // array(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100)<br /> foreach (range(0, 100, 10) as $number) {<br /> echo $number;<br /> }<br /> <br /> // Use of character sequences introduced in 4.1.0<br /> // array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i');<br /> foreach (range('a', 'i') as $letter) {<br /> echo $letter;<br /> }<br /> // array('c', 'b', 'a');<br /> foreach (range('c', 'a') as $letter) {<br /> echo $letter;<br /> } <br /> <br /> <br /> list<br /> list -- 把数组中的值赋给一些变量 <br /> <!--p<br--> $info = array('coffee', 'brown', 'caffeine');<br /> // Listing all the variables<br /> list($drink, $color, $power) = $info;<br /> echo &quot;$drink is $color and $power makes it special.n&quot;;<br /> // Listing some of them<br /> list($drink, , $power) = $info;<br /> echo &quot;$drink has $power.n&quot;;<br /> // Or let's skip to only the third one<br /> list( , , $power) = $info;<br /> echo &quot;I need $power!n&quot;;<br /> ?&gt; <br /> <br /> exit<br /> exit -- Output a message and terminate the current script<br /> 例子 1. exit() example<br /> <!--p<br--> $filename = '/path/to/data-file';<br /> $file = fopen($filename, 'r')<br /> or exit(&quot;unable to open file ($filename)&quot;);<br /> ?&gt; <br /> <br /> empty<br /> empty -- 检查一个变量是否为空<br /> <br /> parse_str<br /> parse_str -- Parses the string into variables<br /> 例子 1. Using parse_str()<br /> <!--p<br--> $str = &quot;first=value&amp;arr[]=foo+bar&amp;arr[]=baz&quot;;<br /> parse_str($str);<br /> echo $first; // value<br /> echo $arr[0]; // foo bar<br /> echo $arr[1]; // baz<br /> parse_str($str, $output);<br /> echo $output['first']; // value<br /> echo $output['arr'][0]; // foo bar<br /> echo $output['arr'][1]; // baz<br /> ?&gt; <br /> <br /> strcasecmp<br /> strcasecmp -- Binary safe case-insensitive string comparison <br /> Description<br /> int strcasecmp ( string str1, string str2 )<br /> Returns &lt; 0 if str1 is less than str2; &gt; 0 if str1 is greater than str2, and 0 if they are equal. 例子 1. strcasecmp() example<br /> <!--p<br--> $var1 = &quot;Hello&quot;;<br /> $var2 = &quot;hello&quot;;<br /> if (strcasecmp($var1, $var2) == 0) {<br /> echo '$var1 is equal to $var2 in a case-insensitive string comparison';<br /> }<br /> ?&gt;</p>
T:0.006649s,M:255.98 KB
返回顶部 留言