* 得到|返回3行3列表格 */ function getTable1() { $table = '<table border="1" width="60%">'; for ($i = 1; $i <= 3; ++$i) { $table .= '<tr>'; for ($j = 1; $j <= 3; ++$j) { $table .= '<td>x</td>'; } $table .= '</tr>'; } $table .= '</table>'; return $table; } getTable1(); //sdffkljfsdkljsdfjklsdfkljsdf echo '<hr/>'; //输出4行5列的表格 //得到2015年8月21日 星期五 /** * 得到2015年8月21日 星期五 * @return string */ function getDateStr() { $search = array(0, 1, 2, 3, 4, 5, 6); $replace = array('日', '一', '二', '三', '四', '五', '六'); $string = date('w'); return date("Y年m月d日 星期") . str_replace($search, $replace, $string); }
} echo '</table>'; } echo '<hr/>'; //必选参数 /* Warning: Missing argument 1 for getTable1(), called in F:\psd1507\study\PHPCORE\day07\demo\function\func4.php on line 22 and defined in F:\psd1507\study\PHPCORE\day07\demo\function\func4.php on line 23 */ getTable1(3, 4); echo '<hr/>'; $i = 5; $j = 6; getTable1($i, $j); echo '<hr/>'; getTable1(7, 9); function getTable1($rows, $cols) { echo '<table border="5" width="60%">'; for ($i = 1; $i <= $rows; ++$i) { echo '<tr>'; for ($j = 1; $j <= $cols; ++$j) { echo '<td>x</td>'; } echo '</tr>'; } echo '</table>'; } echo '<hr color="red"/>'; //可选参数 //默认创建3行4列的表格
header('content-type:text/html;charset=utf-8'); // 0.默认得到3行3列的表格,颜色默认是天蓝色,内容默认是x function getTable1($cols = 5, $rows = 4, $bgcolor = 'blue', $content = '你好') { $abb = "<table border='1' cellpadding='0' cellspacing='0' width=60% background-color='{$bgColor}'>"; for ($i = 1; $i <= $cols; $i++) { $abb .= '<tr>'; for ($j = 1; $j <= $rows; $j++) { $abb .= "<td>{$content}</td>"; } $abb .= '</tr>'; } $abb .= "</table>"; return $abb; } echo getTable1(); echo '<hr />'; // 1.给你一个文件名1.txt 1.jpeg 1.txt.png, // 得到文件的扩展名 function getH($aa) { $hzm = @strtolower(end(explode('.', $aa))); return $hzm; } echo getH('1.txt.php'); // 2.默认得到日期2015年8月21日 星期五 // 2015-8-21 星期五 2015/8/21 星期五 echo '<hr />'; function getTime($del1 = '年', $del2 = '月', $del3 = '日') { $str = date('w');