背景:远在北京的高中女同学让我帮忙当她的实训“技术顾问”,实训要求个人独立开发一个web项目,她选择的开发语言是php。其实我又当了一次标题党,她虽然以前从来没用过PHP,但是却有一点点html、css、javascript基础(据说已经忘光了),有用过C和java写过东西。
项目描述:
题目——资源预定管理系统
功能需求——
1. 针对企事业单位开发一个资源预定管理系统
2. 针对不同类别的资源,例如会议室、汽车、仪器设备等,向员工提供预约使用的功能
3. 员工登录系统后,可以查看指定的资源当前的预定情况,可以预定指定时间段内空闲的资源。
4. 不同的资源需要根据情况设置不同开放时间,例如每天的8:00到18:00,用于智能在开发时间内进行预定
5. 不同的资源可以预定的最小时间单位是不同的,例如会议室按分钟进行预定,最短15分钟,汽车按小时预定,最短2个小时。
6. 系统遵循先到先得的原则进行预定。
7. 用户预定后,尚未使用前可以取消,取消后,其它用户可以继续预定
第一步:写需求文档
计算机专业的同学一般都上过软件工程这门课,自然知道做需求的重要性。就算没上过,有过工作经验的同志们也应该看过别人写的需求文档。如果把一个项目的完成比作造房子,那么需求就好比建筑设计图,如果设计的不好,那么造出来的房子也不会好看。虽然软件开发比建筑有更大的灵活性(起码房子不能动不动就回滚代码,撤销更改),但是需求要是做得不全面不严格,往往会极大地增加不必要的工作量和降低工作效率。
你想想,今天告诉你这样一个需求,你代码写了一半,过几天告诉你需求改了,之前的代码都没用了,你什么感觉?虽然需求变更是常有的事,但是一旦需求发生失控,对项目的影响往往是灾难性的。
幸好妹子之前做桌面软件课程设计的时候写过需求文档,不然要从头开始学怎么做需求还是一件蛮麻烦的事情。但如果刚入门的童鞋嫌麻烦不做需求是大大的不妥,且不论进入正式工作后要接触更为严格严谨的需求文档,哪怕只是应付学校里的课程设计,在软件规模足够大的情况下,做需求用一天的时间,起码可以使开发的时间缩短一个星期。
第二步:登录页面的举例
妹子写需求文档去了,那我也不能闲着。因为我之前只是稍微看过php的相关资料,并没有用过php写过一行代码,为了走在妹子前面,必须要提前学习妹子要用的东西。由于这个课程设计的项目有登录的功能,所以我打算用这个页面作为介绍php的第一个例子,并且往后还会就登录功能整个流程进行更加详尽的说明。
首先,我们看一个最简单的html登录页面,上代码!
<ol class="dp-xml"> <li class="alt"><span><span class="tag"><span class="tag-name">html</span><span class="tag">></span><span> </span></span></span></li> <li> <span> </span><span class="tag"><span class="tag-name">head</span><span class="tag">></span><span> </span></span> </li> <li class="alt"> <span> </span><span class="tag"><span class="tag-name">meta</span><span> </span><span class="attribute">charset</span><span>=</span><span class="attribute-value">"gbk"</span><span class="tag">></span><span> </span></span> </li> <li> <span> </span><span class="tag"><span class="tag-name">title</span><span class="tag">></span><span>用户登录界面</span><span class="tag"></span><span class="tag-name">title</span><span class="tag">></span><span> </span></span> </li> <li class="alt"> <span> </span><span class="tag"></span><span class="tag-name">head</span><span class="tag">></span><span> </span> </li> <li> <span> </span><span class="tag"><span class="tag-name">body</span><span class="tag">></span><span> </span></span> </li> <li class="alt"> <span> </span><span class="tag"><span class="tag-name">form</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"login"</span><span> </span><span class="attribute">action</span><span>=</span><span class="attribute-value">"Controller.php"</span><span> </span><span class="attribute">method</span><span>=</span><span class="attribute-value">"post"</span><span> </span><span class="tag">></span><span> </span></span> </li> <li> <span> </span><span class="tag"><span class="tag-name">td</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">"tbl"</span><span class="tag">></span><span>用户名:</span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span class="tag"><span class="tag-name">td</span><span class="tag">></span><span class="tag"><span class="tag-name">input</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text"</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"user_id"</span><span class="tag">></span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span> </span></span></span></span> </li> <li class="alt"> <span> </span><span class="tag"><span class="tag-name">td</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">"tbl"</span><span class="tag">></span><span>密码:</span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span class="tag"><span class="tag-name">td</span><span class="tag">></span><span class="tag"><span class="tag-name">input</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text"</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"user_password"</span><span class="tag">></span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span> </span></span></span></span> </li> <li> <span> </span><span class="tag"><span class="tag-name">td</span><span class="tag">></span><span class="tag"><span class="tag-name">input</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"submit"</span><span> </span><span class="attribute">value</span><span>=</span><span class="attribute-value">"登入系统"</span><span class="tag">></span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span> </span></span></span> </li> <li class="alt"> <span> </span><span class="tag"></span><span class="tag-name">form</span><span class="tag">></span><span> </span> </li> <li> <span> </span><span class="tag"></span><span class="tag-name">body</span><span class="tag">></span><span> </span> </li> <li class="alt"> <span class="tag"></span><span class="tag-name">html</span><span class="tag">></span><span> </span> </li> </ol>
为了让大家不当极致的伸手党,我就不把页面截图上来了,大家自己复制代码用浏览器看看效果。为什么我要给妹子写这几行代码呢?主要是想让妹子重新熟悉一下html代码长什么样子,而且是为了下面让妹子知道php与html为什么混合在一起做铺垫。过了这么一会儿,大家应该已经看过上面那些代码的显示效果了吧。既然这样,请看下面加入php后的代码:
<ol class="dp-xml"> <li class="alt"><span><span class="tag"></span><span class="tag-name">php</span><span> //php代码部分开始 </span></span></li> <li> <span>echo "</span><span class="tag"><span class="tag-name">html</span><span class="tag">></span><span>"; </span></span> </li> <li class="alt"> <span>echo "</span><span class="tag"><span class="tag-name">head</span><span class="tag">></span><span>"; </span></span> </li> <li> <span>echo "</span><span class="tag"><span class="tag-name">meta</span><span> </span><span class="attribute">charset</span><span>=\"gbk\"</span><span class="tag">></span><span>"; </span></span> </li> <li class="alt"> <span>echo "</span><span class="tag"><span class="tag-name">title</span><span class="tag">></span><span>用户登录界面</span><span class="tag"></span><span class="tag-name">title</span><span class="tag">></span><span>"; </span></span> </li> <li> <span class="tag">?></span><span class="comments"><!-- php代码部分结束--></span><span> </span> </li> <li class="alt"> <span class="tag"></span><span class="tag-name">head</span><span class="tag">></span><span> </span> </li> <li><span class="tag"><span class="tag-name">body</span><span class="tag">></span><span> </span></span></li> <li class="alt"><span class="tag"><span class="tag-name">form</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"login"</span><span> </span><span class="attribute">action</span><span>=</span><span class="attribute-value">"Controller.php"</span><span> </span><span class="attribute">method</span><span>=</span><span class="attribute-value">"post"</span><span> </span><span class="tag">></span><span> </span></span></li> <li> <span> </span><span class="tag"><span class="tag-name">td</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">"tbl"</span><span class="tag">></span><span>用户名:</span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span class="tag"><span class="tag-name">td</span><span class="tag">></span><span class="tag"><span class="tag-name">input</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text"</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"user_id"</span><span class="tag">></span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span> </span></span></span></span> </li> <li class="alt"> <span> </span><span class="tag"><span class="tag-name">td</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">"tbl"</span><span class="tag">></span><span>密码:</span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span class="tag"><span class="tag-name">td</span><span class="tag">></span><span class="tag"><span class="tag-name">input</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text"</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"user_password"</span><span class="tag">></span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span> </span></span></span></span> </li> <li> <span class="tag"></span><span class="tag-name">php</span><span> </span> </li> <li class="alt"> <span>echo "</span><span class="tag"><span class="tag-name">td</span><span class="tag">></span><span class="tag"><span class="tag-name">input</span><span> </span><span class="attribute">type</span><span>=\"submit\" </span><span class="attribute">value</span><span>=\"登入系统\"</span><span class="tag">></span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span>" </span></span></span> </li> <li> <span class="tag">?></span><span> </span> </li> <li class="alt"> <span class="tag"></span><span class="tag-name">form</span><span class="tag">></span><span> </span> </li> <li> <span class="tag"></span><span class="tag-name">body</span><span class="tag">></span><span> </span> </li> <li class="alt"> <span class="tag"></span><span class="tag-name">html</span><span class="tag">></span><span> </span> </li> </ol>
这段代码主要让妹子了解这么几点:(1)php代码要用标签进行标识(2)如何使用echo语句进行输出html代码,另外关于要用对""中的"(双引号)用\(转义符)进行转义。(3)php代码是如何跟html代码进行混合的。
PS:完事开头难,第一篇文章就先写这么多。起点定的太高反而不好,容易把初学者搞迷糊了。多看作为例子的代码,自己动手改一改,写一写,感受一下。
原文链接:http://www.cnblogs.com/levenyes/archive/2013/09/04/3299146.html

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Linux new version
SublimeText3 Linux latest version

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
