华北科技学院管理学院实验报告册
实验报告
实验时间: 2015 年11 月 11 日节
一、实验运行环境
Windows2000++
二、实验目的
1、掌握正则表达式的使用方法
2、掌握php获取html表单数据的方法
3、掌握php中的文件处理的使用方法
4、掌握类的创建方法及应用
三、实验要求
1、某表单及验证表单的程序如3-1文件夹,请运行该程序并理解文件中的正则表达式。
<php
$filename = 'hello/';
$somecontent = "我先被写入的!\r\n";
$somecontent1 = "我后被写入的!\r\n";
1 a
2 a
3 a
4 a
5 a
myf ile_name);
}
>
<form enctype="multipart/form-data"
action="" method="post">
您的姓名: <input type=text name=user><br>
文件名称: <input name="myfile" type="file"><br>
<input type="hidden" name="post_flag" value="1">
<input type="submit" value="提交">
</form>
<php
$myfile = $_FILES['myfile']['tmp_name'];
if($myfile != "")
{
if(copy($myfile,$_FILES['myfile']['name'])) {
echo "上传成功";
} else
{
echo "上传失败";
}
unlink($myfile);
} else
{
echo "没有可上传的文件";
}
>
8、利用php中的文件处理技术编写程序如下:请运行该程序并理解。
<php
$filename = 'hello/';
$somecontent = "我先被写入的!\r\n";
$somecontent1 = "我后被写入的!\r\n";
oo::$my_stat ic . "<br>";
$foo = new Foo(); "<br>"; "<br>"; "<br>";
$bar = new Bar();
print $bar->fooStatic() ;
upl oad->errmsg();
}}>
12、php显示中文时,经常出现乱码,请编写一个编码转换类,从而实现编码的自动转换。
<php
class changecode{
private $str;
private $input;
private $output;
function __construct($input='',$output='gb2312'){
$this->input = $input;
$this->output = $output;
}
protected function chgcode($str){
if($this->input != ''){
$this->str = iconv($input,$output,$str);
}else{
$this->str = mb_convert_encoding($str,$output);
}
<php
include_once "";
if($_POST['name'] != "范春喜"){
$tm -> refurbish('用户名错误');
}else{
$tm -> skipachange('登陆成功','');
}
>
<php
class TakeMsg{
function __construct(){
}
function simpleMsg($mess){
echo $mess;
}
function skipachange($mess,$url=NULL){
if(!is_null($url)){
echo "<script>alert('".$mess."');location='".$url."';</script>";
}else{
echo "<script>alert('".$mess."');;</script>";
}
}
function refurbish($mess,$sec=3,$url=NULL){
if(is_null($url)){
$hr = $_SERVER['HTTP_REFERER'];
echo $mess.'<br>';
echo '页面将于'.$sec.'秒后跳转。
如果没有跳转,请点击这里<a href="'.$hr.'">返回</a>';
echo '<meta http-equiv="refresh" content="'.$sec.';url='.$hr.'"/>';
}else{
echo $mess.'<br>';
echo '页面将于'.$sec.'秒后跳转。
如果没有跳转,请点击这里<a href="'.$url.'">返回</a>';
echo '<meta http-equiv="Refresh" content="'.$sec.';url='.$url.'">';
}
}
}
$tm = new TakeMsg();
>
<php
include_once "";
$tm -> simpleMsg('欢迎光临');
>
实验报告说明
1、要求每一实验项目书写一份实验报告,并按实验课程归类汇总。
2、实验报告要遵照实验指导书和任课教师的具体要求逐项填写。
3、实验报告正文要求字迹清晰、工整,用钢笔、中性笔或圆珠笔书写。
4、实验报告封面不得有空缺项;实验项目序号指实验项目编号,如:实验一。
5、实验运行环境之具体实验室和运行软件。
6、实验内容和步骤如书写不够,可加页。