【第二天学习PHP的心得和总结】
时间:2008-05-28
来源:互联网

- 昨天学习到类了,其实是视频教程看到类的内容,但是书上只看到了字符串前。我是两者交叉的,感觉还不错。 在这里推荐一下: 书《PHP与MySQL基础教程》;视频教程:《PHP+MYSQL网站设计入门实践》;ChinaItlab下载的,其实是从学校的FTP服务器下载的,大小是1.70G。
- 不过有点可惜的,时区设置的问题还是没有解决,只能用 date_default_timezone_set("Asia/Chongqing"); 解决问题。是个遗憾。 不过,知道了PHPChina 出的 《phper》,觉得很不错。我觉得很庆幸,因为才接触PHP两天就发现了这么好的杂志,就全部下载收藏了。不过还得加强实力,才能看得比较顺手。
- 呵呵,今天是从字符串开始的。
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body>
<?php
$first_name = 'Nick'; //字符串赋值
$last_name = 'Hornby';
$book = 'High Fidelity';
echo "The book <i>$book</i> was written by $first_name$last_name.";
?>
</body>
</html>
我得说明一下,输入的时候注意要是英文哦,半角的:)
- 接下来是更进一步的字符串内容:
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body>
<?php
$city = 'Quanzhou';
$province = 'Fujian';
$country = 'China'; //字符串赋值
$place = $country.' '.$province.' '.$city ; // . 是连接符号,注意,是“ . ”
echo "<br>$place";
$len = strlen($place); //这个和C很像,呵呵,取字符串的长度
echo "<br>length of $place is $len.";
$upplace = strtoupper($place); //大写全部
$lowplace = strtolower($place); //小写全部
$firstup = ucfirst($lowplace); //大写第一个字母
$words = ucwords($lowplace); //大写每个单词的第一个字母
echo "<br>$upplace<br>$lowplace<br>$firstup<br>$words";
?> //这边发布后会变成 > --#
</body>
</html>
2.使用数字:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body>
<?php
$num = 3.1415926;
$num1 = 1234567.098;
$a = round($num); //四舍五入取最近的整数
$b = round($num,3); //同上,并且保留3个小数
$c = number_format($num1); //转化成规格,即3位一个逗号,100,000
$d = number_format($num1,2); //同上,并且保留2位小数
echo "<br>$num<br>$num1<br>$a<br>$b<br>$c<br>$d"
?>
</body>
</html>
3.常量和引号的学习:
这部分我觉得举例下比较明了:
$var = test ;
echo "var is equal to $var"; // 显示 var is equal to test
echo "\$var is equal to $var“; // 显示 $var is equal to test
echo 'var is equal to $var'; // 显示 var is equal to $var
echo '\$var is equal to $var'; // 显示 \$var is equal to $var
而当在双引号内要引用一些特殊字符时,
代码 显示
\" "
\' '
\\ \
\n 换行 //不过我一直失败!……
\r 回车 //不过我没有尝试过
\t 制表 //还是没尝试过
\$ $
4.表单的学习
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Simple HTML Form</title>
</head>
<body>
<form action="handle_form.php" method="POST";> <!-- 插入表格,用handle_form.php处理数据,传递方式为POST -->
<fieldset>
<legend>Enter your information in the form below:</legend>
<p><b>Name:</b> <input type="text" name="name" size="20" maxlength="40"/></p>
<p><b>Email Address:</b> <input type="text" name="email" size="40" maxlength="60" /></p>
<p><b>Gender:</b><input type="radio" name="gender" value="M" />Male
<input type="radio" name="gender" value="F" />Female</p>
<p><b>Age:</b>
<select name="age">
<option value="0-29">Under 30</option>
<option value="30-60">Between 30 and 60</option>
<option value="60+">Over 60</option>
</select></p>
<p><b>Comments:</b><textarea name="comments" rows="3" cols="40"></textarea></p>
</fieldset>
<div align="center"><input type="submit" name="submit" value="Submit My Information" /></div>
</form>
</body>
</html>
如果没有学习过HTML,我建议http://www.gzsums.edu.cn/webclass/html/html_design.html
当然,也可以给我邮箱,我发给你教程 :)
5.表单的处理: // 我都有注释
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Form Feedback</title>
</head>
<body>
<?php
$name = stripslashes($_REQUEST['name']); //stripslashes()抵消Magic Quotes的作用,并删除不必要的反斜杠
$email = $_REQUEST['email']; //$_REQUEST[]获得传递的变量
$comments = stripcslashes($_REQUEST['comments']); //trim($name)可以删除两端多余的空白
echo "<p> Thank you,<b>$name</b>,for the following comments:<br>
<tt>$comments</tt></p>
<p>We will reply to you at <i>$email</i>.</p><br>";
if (isset($_REQUEST['gender'])) //判断$_REQUEST['gender']的值是否为NULL
{
$gender = $_REQUEST['gender'];
}
else { $gender = NULL;
}
if ($gender == 'M'){ echo '<p>Good day,Sir!</p><br>'; }
elseif ($gender == 'F') { echo '<p>Good day , Madam!</p><br>'; }
else { echo 'You forgot to select your gender!<br>'; }
?>
</body>
</html>
6.表单的处理2 :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body>
<?php
if (!empty($_REQUEST['name'])){ //检查name传递过来的值是否为NULL或者空字符或者0
$name = stripcslashes($_REQUEST['name']);
}else {
$name = NULL;
echo '<p><font color="red">You forgot to enter your name!</font></p>';
}
if (!empty($_REQUEST['email'])){
$email = $_REQUEST['email'];
}else {
$email = NULL;
echo '<p><font color="red">You forgot to enter your email address!</font></p>';
}
if(!empty($_REQUEST['comments'])){
$comments = $_REQUEST['comments'];
}else {
$comments = NULL;
echo '<p><font color="red">You forgot to enter your comments!</font></p>';
}
if(isset($_REQUEST['gender'])){ //is_numric()函数可以用来测试提交的值是否是数字
$gender = $_REQUEST['gender'];
if ($gender == 'M'){
echo 'Good day,Sir!';
}
elseif ($gender == 'F'){
echo 'Good day,Madam!';
}else{
echo '<p><font color="red">You forgot to select your gender!</font><p>';
}
}else{
$gender=NULL;
echo '<p><font color="red">You forgot to select your gender!</font></p>';
}
if ($name && $email && $gender && $comments){
echo '<p>Thank you.<b>'.$name.'</b>,for the following comments:<br>';
echo "<tt>$comments</tt></p>";
echo "<p>We will reply to you at <i>$email</i>.</p><br>";
}else{
echo '<p><font color="red">Please go back and fill out the form again.</font></p>';
}
?>
</body>
</html>
呵呵 ,其实还有在视频教程稍微接触到for 和 数组,不过可能接下去要在书上学习,就先保留了 :)
[ 本帖最后由 casual0402 于 2008-5-27 21:02 编辑 ]
作者: casual0402 发布时间: 2008-05-27


作者: luzhou 发布时间: 2008-05-28
初步看了一下,感觉不太想笔记,倒像是把例子统统打了一遍,不知道意义何在,没有自己的体会在里面
作者: ct_174880859 发布时间: 2008-05-28
呵,我也觉得,其实是自己复习了一遍当天学过的;
我会改进的,谢谢
我会改进的,谢谢

作者: casual0402 发布时间: 2008-05-28
不过,我觉得初学者刚开始是需要实例来了解和深入的;
所以我觉得例子是比较重要的
而我自己觉得比较值得注意的都会注释一下
所以我觉得例子是比较重要的
而我自己觉得比较值得注意的都会注释一下
作者: casual0402 发布时间: 2008-05-28
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28