PHP笔记

环境地址
apache + php + mysql
 
开发工具地址:
eclipsePHP Studio
标记风格
<?php ... ?>  (推荐)
或<% ... %>
 
数据检测
is_bool     is_null     is_array     is_object 
is_string    is_int
 
implode   字符串转数组
explode   数组转字符串
 
array_push       向数组中添加元素
array_unique   删除数组中重复元素
 
全局变量  $_GET[变量名]
局部变量  $_POST[变量名]
获取表单元素的值  $_SESSION[..]
 
页面包含  <?php include 'url.php';?>  
<?php
//二维数组
echo '二维数组<br>';
$str = array(
       "书籍" => array("文学","历史","地理"),
   "体育用品" => array(m=>"足球",n=>"篮球"),
   "水果" => array("橙子",8=>"葡萄","苹果"));
print_r($str);
 
//数组遍历
echo '<br><br>数组遍历<br>';
$url = array('编程词典网'=>'www.mrbccd.com', '编程体验网'=>'www.bcty365.com', '编程资源网'=>'www.bc110.com');
foreach($url as $link){
  echo $link.'<br>';
}
 
//+为运算符, .为连接符
echo '数组个数:' . count($url);
?>
 
cookie.php
<?php
setcookie("TMCookie", "www.test.com", time()+3600);
echo $_COOKIE["TMCookie"];
//删除cookie 
//setcookie("TMCookie", "", 0);
?>
 
img_test.php
<?php
header("content-type:image/jpeg");
$im = imagecreatefromjpeg("1.jpg");
$textcolor = imagecolorallocate($im,58,73,136);
imagejpeg($im);
imagedestroy($im);
?>
 
read_file.php
<?php
$fopen = fopen("1.txt",'rb');
while(!feof($fopen)){
    echo fgets($fopen);
echo '<br>';
}
fclose($fopen);
?>
 
 
session.php
<?php
$time = 1*60;
session_set_cookie_params($time);
session_start();
$_SESSION['admin']='admin';
echo $_SESSION['admin'];
?>
 
 
<?php
$link = mysql_connect("localhost", "root", "passw0rd") or die("连接失败".mysql_error());
if($link){
  echo "数据库连接成功!";
}
$db_selected = mysql_select_db("test", $link);
if($db_selected){
  echo "数据库选择成功!";
}
mysql_query("set names gb2312");
$sql = mysql_query("select * from tb_admin");
$info = mysql_fetch_array($sql);
?>
 
search.php
<table>
<?php
do{
?>
<tr>
  <td><?php echo $info[user]; ?></td>
  <td><?php echo $info[password]; ?></td>
  <td><?php echo $info[createtime]; ?></td>
</tr>
<?php
}while($info=mysql_fetch_array($sql));
?>
</table>
 
 
check_add_admin.php
<?php
  $conn = mysql_connect("localhost", "root", "passw0rd");
  mysql_select_db("test", $conn);
  mysql_query("set names gb2312");
  $user = $_POST[user];
  $password = $_POST[password];
  $createtime = date("Y-m-d H:i:s");
  $sql = mysql_query("insert into tb_admin(user,password,createtime) values('$user','$password','$createtime')");
  echo "<script>alert('添加成功');window.location.href='add_admin.php';</script>";
  mysql_free_result($sql);
  mysql_close($conn);
?>
posted @ 2018-12-29 11:42  大飞90  阅读(140)  评论(0编辑  收藏  举报