基础程序题
用PHP打印出前一天的时间格式是2006-5-10 22:21:21
date('Y-m-d H:i:s', strtotime('-1 day'));
<?phpfunction reverse($var) { $res = ""; for($i = 0, $j = strlen($var);$i<$j;$i++) { $res = $var[$i].$res; } return $res;}$tmpvar = "wofang";$res = reverse($tmpvar);echo $res;?>
<?php echo strrev("Hello world!"); // outputs "!dlrow olleH" ?>
<?php /** * 遍历目录,结果存入数组。支持php4及以上。php5以后可用scandir()函数代替while循环。 * @param string $dir * @return array */function my_scandir( $dir ) { $files = array(); if ( $handle = opendir( $dir ) ) { while ( ($file = readdir( $handle )) !== false ) { if ( $file != '..' && $file != '.' ) { if ( is_dir( $dir . '/' . $file ) ) { $files[$file] = rec_scandir( $dir . '/' . $file ); } else { $files[] = $file; } } } closedir( $handle ); return $files; }}?>
<?phpfunction checkEmail( $email ) { $preg = "/([a-z0-9]*[-_\.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?/i"; return preg_match( $preg, $email );}?>
<?php $readcontents = fopen('http://www.phpers.com/index.html');$contents = stream_get_contents($readcontents);fclose($readcontents);echo $contents;?>
<?php echo file_get_contents('http://www.phpers.com/index.html'); ?>
<?php /** * 排序类 */class Sort { /* * 冒泡排序 小到大 */ public function bubble_sort( $array ) { $count = count( $array ); if ( $count <= 0 ) return false; for ( $i = 0; $i < $count; $i++ ) { for ( $j = 1; $j <= $count - $i - 1; $j++ ) { if ( $array[$j] < $array[$j - 1] ) { $tmp = $array[$j]; $array[$j] = $array[$j - 1]; $array[$j - 1] = $tmp; } } } return $array; } /** * 快速排序 */ public function quick_sort( $arr ) { $len = count( $arr ); if ( $len <= 1 ) return $arr; $key = $arr[0]; $left_arr = $right_arr = array(); for ( $i = 1; $i < $len; $i++ ) { if ( $arr[$i] <= $key ) $left_arr[] = $arr[$i]; else $right_arr[] = $arr[$i]; } $left_arr = $this->quick_sort( $left_arr ); $right_arr = $this->quick_sort( $right_arr ); return array_merge( $left_arr, array( $key ), $right_arr ); } /** * 希尔排序 */ public function shell_sort( $datas ) { //分组 for ( $increment = count( $datas ) / 2; $increment > 0; $increment = $increment / 2 ) { //每个组内排序 for ( $i = $increment; $i = $increment; $j = $j - $increment ) { if ( $temp
<?php $a = 1; $b = 2; list($b, $a) = array($a, $b);?>
<?phpfunction getExt($url){ $arr = parse_url($url); $file = basename($arr['path']); $ext = explode(".", $file); return $ext[1];}?>
<?phpfunction getExt($url) { $url = basename($url); $pos1 = strpos($url, "."); $pos2 = strpos($url, "?"); if(strstr($url, "?")){ return substr($url, $pos1 + 1, $pos2 - $pos1 - 1); } else { return substr($url, $pos1); }}?>
<?php function getRelativePath( $a, $b ) { $returnPath = array( dirname( $b ) ); $arrA = explode( '/', $a ); $arrB = explode( '/', $returnPath[0] ); for ( $n = 1, $len = count( $arrB ); $n < $len; $n++ ) { if ( $arrA[$n] != $arrB[$n] ) { break; } } if ( $len - $n > 0 ) { $returnPath = array_merge( $returnPath, array_fill( 1, $len - $n, '..' ) ); } $returnPath = array_merge( $returnPath, array_slice( $arrA, $n ) ); return implode( '/', $returnPath ); } echo getRelativePath( $a, $b );?>