码迷,mamicode.com
首页 > Web开发 > 详细

PHP练习

时间:2016-12-07 13:42:00      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:表示   header   block   rand   har   cte   pen   image   pre   

技术分享
<?php 
     function table($row,$col,$c){
         $str= "<table border=1>";
         for ($i=0; $i <$row ; $i++) { //$i表示行 0~9
             $color=$i % 2==0?"#ffffff":$c;//三元运算符  $i % 2==0为true 执行$color="#fff" 否则 执行 $color="#ccc";
             $str=$str. "<tr bgcolor=$color>";
               for ($j=0; $j <$col ; $j++) { //$j:0~9
                 $str=$str. "<td>".($j+$i*$col)."</td>";
              }
             $str=$str. "</tr>";
        }
       $str=$str. "</table>";

       return $str;
   }
   echo table(10,10,"red");
   echo "<br>";
   echo table(5,5,"green");



header("content-type:html/text;charset=utf-8");
function genPassword($min = 5, $max = 8)  
{  
    $validchars="abcdefghijklmnopqrstuvwxyz1234567890";  
    $max_char=strlen($validchars)-1;  
    $length=mt_rand($min,$max);  
    $password = "";  
    for($i=0;$i<$length;$i++ )  
    {  
        $password.=$validchars[mt_rand(0,$max_char)];  
    }  
        return $password;  
}
echo "生成的密码:".genPassword(5,5)."<br>";  

 ?>
View Code


随机密码,表格

PHP练习

标签:表示   header   block   rand   har   cte   pen   image   pre   

原文地址:http://www.cnblogs.com/tcheng/p/6140612.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!