一、简答题
1.用PHP打印出今天的时间,格式是2009-9-2 22:21:21 2009-09-02 22:21:21
~~~
date(“Y-m-d H:i:s”,time()); date(“Y-n-j H:i:s”);
~~~
2.有一个网页地址, 比如PHP开发资源网主页:[http://www.xxx.com/index.html,如何得到它的内容](http://www.xxx.com/index.html,%E5%A6%82%E4%BD%95%E5%BE%97%E5%88%B0%E5%AE%83%E7%9A%84%E5%86%85%E5%AE%B9)?
~~~
$str = file_get_contents(‘http://www.xxx.com/index.html’);
~~~
3.写出发贴数最多的十个人名字的SQL,利用下表:members(id,username,posts,pass,email)
~~~
$sql = “select username from members order by posts desc limit 0,10”;
~~~
4.在PHP中error\_reporting这个函数有什么作用?
~~~
打开或者关闭错误报告 //error_reporting(0); error_reporting(E_ALL ^ E_NOTICE); error_reporting(E_ALL);
~~~
5.func()和@func()之间有什么区别?
~~~
第二个函数调用失败不会报错,第一个会报错
~~~
6.mysql\_fetch\_row() 和mysql\_fetch\_assoc()和mysql\_fetch\_array之间有什么区别?
~~~
第一个是返回结果集中的一行作为索引数组,第二个是返回关联数组,而第三个既可以返回索引数组也可以返回关联数组,取决于它的第二个参数 MYSQL_BOTH MYSQL_NUM MYSQL_ASSOC 默认为MYSQL_BOTH
$sql =”select * from table1”;
$result = mysql_query($sql);
mysql_fetch_array($result, MYSQL_NUM);
~~~
7.写出以下程序的输出结果
<?
$b=201;
$c=40;
$a= $b>$c?4:5;
echo $a;
?>
~~~
答案:4
~~~
8.取得查询结果集总数的函数是?
~~~
mysql_num_rows($result)
~~~
9.取得增删改等操作所影响的行数的函数是什么?
~~~
mysql_affected_rows($result) 不写参数则返回最近一次操作的结果集 失败返回-1
~~~
10.取得最新一次添加记录(假设id为主键,并且是自增类型)所产生的id的函数是什么?
~~~
mysql_insert_id();如果上一查询没有产生 AUTO_INCREMENT 的值,则 mysql_insert_id() 返回 0
~~~
11.$arr = array('james', 'tom', 'symfony'); 请将’jack’添加到$arr数组的开头,并把jack打印出来
~~~
array_unshift($arr,’jack’); echo $arr[0];
~~~
12.$arr = array('james', 'tom', 'symfony');请将$arr数组的值用’,’分割并合并成字符串输出?
~~~
echo implode(‘,’,$arr);
~~~
13.$str = ‘jack,james,tom,symfony’; 请将$str用’,’分割,并把分割后的值放到$arr数组中?
~~~
$arr = explode(‘,’,$str);
~~~
14.$arr = array(3,7,2,1,’d’,’abc’); 请将$arr按照从大到小的顺序排序,并保持其键值不变?
~~~
arsort($arr); print_r($arr);
~~~
15.$mail = “gaofei@163.com”; 请将此邮箱的域([163.com](http://163.com/))取出来并打印,看最多能写出几种方法?
~~~
echo strstr($mail,'163');
echo substr($mail,7);
$arr = explode("@",$mail); echo $arr[1];
~~~
16.php连接mysql之后,如何设置mysql的字符集编码为utf8?
~~~
mysql_query(“set names utf8”);
~~~
17.php程序中如何设置当前页面的编码为utf-8?
~~~
header(“content-type:text/html;charset=utf-8”);
~~~
18.如果我的网站用的utf-8编码,为防止乱码出现,都需要注意哪些地方?
~~~
1数据库中库和表都用utf8_general_ci编码
2 php连接mysql,指定数据库编码为utf8 mysql_query(“set names utf8”);
3 php文件指定头部编码为utf-8 header(“content-type:text/html;charset=utf-8”);
4网站下所有文件的编码为utf8
5 html文件指定编码为utf-8 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
~~~
19.php中,如何跳转到blog/view.php页面,请用函数实现?
~~~
header(“location:blog/view.php”);
~~~
20.在url中用get传值的时候,若中文出现乱码,应该用哪个函数对中文进行编码?
~~~
urlencode()
~~~
21.用户在网站表单提交数据的时候,为了防止脚本攻击(比如用户输入),php端接收数据的时候,应该如何处理?
~~~
htmlspecialchars($_POST[‘title’]);
~~~
22.写出两种对变量加密的函数?
~~~
md5($str); sha1($str);
~~~
23.如何设置一个cookie的名字为username,值为jack,并且让此cookie一周后失效?
~~~
setcookie(‘username’,’jack’,time()+7*24*3600);
~~~
24.一个浏览器做多可以产生多少个cookie,每个cookie文件最大不能超过多少?
~~~
20个,每个做多不超过4K
~~~
25.设置或读取session之前,需要做什么?
~~~
可以直接在php.ini中开启session.auto_start = 1或者在页面头部用session_start();开启session,session_start()前面不能有任何输出,包括空行。
~~~
26.使用setcookie函数前,需要注意什么?
~~~
前面不能有任何输出,包括空行。
~~~
27.$str=”你好baby好久不见了!”; 如何页面编码为utf-8格式,我要截取12个字符,不出现乱码,应该用什么函数?
~~~
echo $str2 = mb_substr($str,12);
自定义函数吧
~~~
28.如何把2009-9-2 10:30:25变成unix时间戳?
~~~
$unix_time = strtotime("2009-9-2 10:30:25");//变成unix时间戳
echo date("Y-m-d H:i:s",$unix_time);//格式化为正常时间格式
~~~
二、选择题
1.下面哪个函数可以打开一个文件,以对文件进行读和写操作?
~~~
(c)
~~~
(a) fget() (b) file\_open() (c) fopen() (d) open\_file()
2.下面哪个选项没有将 john 添加到users 数组中?
~~~
(b,d)
~~~
(a) $users\[\] = ‘john’;
(b) array\_add($users,’john’);
(c) array\_push($users,‘john’);
(d) $users ||= ‘john’;
3.下面的程序会输出什么?(1分)
~~~
c
~~~
<?php
$num = 10;
function multiply(){
$num = $num \* 10;
}
multiply();
echo $num;
?>
(a) 100 (b) 没有任何输出 (c) 10 (d) 11
三、答题
1.使用php写一段简单查询,查出所有姓名为“张三”的内容放到一个数组中,并用foreach把张三的信息打印到table表格中。
表名User
Name Tel Content Date
张三 13333663366 大专毕业 2006-10-11
张三 13612312331 本科毕业 2006-10-15
张四 021-55665566 中专毕业 2006-10-15
请根据上面的题目完成代码:
~~~
$link = mysql_connect(‘localhost’,’root’,’’) or die(‘连接mysql失败’);
mysql_select_db(‘database1’);
mysql_query(‘set names utf8’);
$sql = “select * from table1 where name=’张三’”;
$result = mysql_query($sql);
while( $row = mysql_fetch_assoc($result) ){
$arr[] = $row;
}
$str .= ‘<table>’;
foreach( $arr as $v ){
$str .= ‘<tr><td>’.$v[‘name’].’</td><td>’.$v[‘age’].’</td><td>’.$v[‘class’].’</td></tr>’;
}
$str .= ‘</table>’;
echo $str;
~~~
2.写出 SQL语句的格式 : 插入 ,更新 ,删除 (4分)
表名User
Name Tel Content Date
张三 13333663366 大专毕业 2006-10-11
张三 13612312331 本科毕业 2006-10-15
张四 021-55665566 中专毕业 2006-10-15
(a) 有一新记录(小王 13254748547 高中毕业 2007-05-06)请用SQL语句新增至表中
~~~
$sql = “insert into User(Name,Tel,Content,Date) values(‘小王’,’13254748547’,’ 高中毕业’,’ 2007-05-06’)”;
~~~
(b) 请用sql语句把张三的时间更新成为当前系统时间
~~~
$sql = “update User set Date=’”.time().”’ Where Name=’张三’”;
~~~
(c) 请写出删除名为张四的全部记录
~~~
$sql = “delete from User where Name=’张四’”;
~~~
3.以下请用PHPMYADMIN完成
(一)创建新闻发布系统,表名为message有如下字段 (3分)
id 文章id
title 文章标题
content 文章内容
category\_id 文章分类id
hits 点击量
(二)同样上述新闻发布系统:表comment记录用户回复内容,字段如下 (4分)
comment\_id 回复id
id 文章id,关联message表中的id
comment\_content 回复内容
现通过查询数据库需要得到以下格式的文章标题列表,并按照回复数量排序,回复最高的排在最前面
文章id 文章标题 点击量 回复数量
用一个SQL语句完成上述查询,如果文章没有回复则回复数量显示为0
SELECT t. \* , (
SELECT count( \* )
FROM COMMENT tt
WHERE[tt.id](http://tt.id/)\=[t.id](http://t.id/)
)num
FROM`message`t order by num desc
LIMIT 0 , 30 ;
(三)上述内容管理系统,表category保存分类信息,字段如下
category\_id int(4) not null auto\_increment;
categroy\_name varchar(40) not null;
用户输入文章时,通过选择下拉菜单选定文章分类
写出如何实现这个下拉菜单
~~~
Function selectCategory($arr)
{
If( empty($arr) ){
Return “<select name=’category’><option>暂无分类</option></select>”;
}
$str = “<select name=’category’><option>文章分类</option>”;
Foreach($arr as $v){
$str.=“<option value=’”.$v[‘category_id’].”’>”.$v[‘category_name’].”</option>”;
}
$str .= “</select>”;
Return $str;
}
~~~
- 简介
- PHP的优势
- PHP运行原理和机制
- PHP7有哪些新特性
- 第一章 PHP
- 基础
- 1、流程控制
- if...else
- switch
- for
- while
- foreach
- 跳出循环
- 2、数组函数
- 数组排序
- sort() - 以正序数组排序
- rsort() - 以降序对数组排序
- asort() - 根据值,以升序对关联数组进行排序
- ksort() - 根据键,以升序对关联数组进行排序
- arsort() - 根据值,以降序对关联数组进行排序
- krsort() - 根据键,以降序对关联数组进行排序
- 数组函数
- array_column() - 返回输入数组中某个单一列的值
- array_merge() - 把一个或多个数组合并为一个数组
- array_search() - 搜索数组中给定的值并返回键名
- array_shift() - 删除数组中首个元素,并返回被删除元素的值
- array_pop() - 删除数组的最后一个元素(出栈)
- array_product() - 计算数组中所有值的乘积
- array_push() - 将一个或多个元素插入数组的末尾(入栈)
- array_rand() - 返回数组中一个或多个随机的键
- array_sum() - 返回数组中值的和
- array_unique() - 删除数组中的重复值
- array_unshift() - 在数组开头插入一个或多个元素
- array_values() - 返回数组中所有的值
- in_array() - 检查数组中是否存在指定的值
- list() - 把数组中的值赋给一些变量
- 3、字符串函数
- strlen() - 返回字符串长度
- substr() - 截取字符串
- str_replace() - 把字符串的一部分替换为另一个字符串
- str_ireplace() - 替换字符串中的一些字符(对大小写不敏感)
- strstr() - 查找字符串在另一字符串中的第一次出现(对大小写敏感)
- stristr() - 查找字符串在另一字符串中第一次出现的位置(大小写不敏感)
- strripos() - 查找字符串在另一字符串中最后一次出现的位置(对大小写不敏感)
- strrpos() - 查找字符串在另一字符串中最后一次出现的位置(对大小写敏感)
- trim() - 移除字符串两侧的空白字符和其他字符
- rtrim() - 移除字符串右侧的空白字符或其他字符
- ltrim() - 移除字符串左侧的空白字符或其他字符
- strrev() - 反转字符串
- explode() - 把字符串打散为数组
- implode() - 数组转换为字符串
- strip_tags() - 剥去字符串中的 HTML 和 PHP 标签
- strtolower() - 把字符串转换为小写字母
- strtoupper() - 把字符串转换为大写字母
- htmlentities() - 把字符转换为 HTML 实体
- html_entity_decode() - 把 HTML 实体转换为字符
- md5() - 计算字符串的 MD5 散列
- md5_file() - 计算文件的 MD5 散列
- sha1() - 计算字符串的 SHA-1 散列
- sha1_file() - 计算文件的 SHA-1 散列
- 4、日期时间
- date() - 函数把时间戳格式化为更易读的日期和时间
- mktime() - 返回日期的 Unix 时间戳
- strtotime - 转化为时间戳
- 第二章 MYSQL
- 简介
- connect - 连接数据库
- create - 创建数据库和表
- insert - 添加数据
- select - 查询数据
- update - 修改数据
- delect - 删除数据
- where - 条件
- order by - 关键词
- 第三章 编辑器
- phpstorm
- 第四章 框架
- thinkphp5.0
- tp安装
- 开发规范
- 目录结构
- 数据库
- 查询数据
- 添加数据
- 更新数据
- 删除数据
- 查询方法
- 查询语法
- 链式操作
- where
- table
- alias
- field
- order
- limit
- page
- group
- having
- join
- union
- distinct
- lock
- cache
- comment
- fetchSql
- force
- bind
- partition
- strict
- failException
- sequence
- 聚合查询
- 时间查询
- 高级查询
- 视图查询
- 子查询
- 原生查询
- 事务操作
- 监听SQL
- 存储过程
- 分布式数据库
- 第五章 服务器
- 阿里云服务器
- linux命令
- nginx
- Nginx搭建负载均衡环境简单实现
- memcached
- redis
- 杂项
- http 状态码
- 消息
- 100 Continue
- 101 Switching Protocols
- 102 Processing
- 成功
- 200 OK
- 201 Created
- 202 Accepted
- 203 Non-Authoritative Information
- 204 No Content
- 205 Reset Content
- 206 Partial Content
- 207 Multi-Status
- 重定向
- 300 Multiple Choices
- 301 Moved Permanently
- 302 Move temporarily
- 303 See Other
- 304 Not Modified
- 305 Use Proxy
- 306 Switch Proxy
- 307 Temporary Redirect
- 请求错误
- 400 Bad Request
- 401 Unauthorized
- 402 Payment Required
- 403 Forbidden
- 404 Not Found
- 405 Method Not Allowed
- 406 Not Acceptable
- 407 Proxy Authentication Required
- 408 Request Timeout
- 409 Conflict
- 410 Gone
- 411 Length Required
- 412 Precondition Failed
- 413 Request Entity Too Large
- 414 Request-URI Too Long
- 415 Unsupported Media Type
- 416 Requested Range Not Satisfiable
- 417 Expectation Failed
- 421 too many connections
- 422 Unprocessable Entity
- 423 Locked
- 424 Failed Dependency
- 425 Unordered Collection
- 426 Upgrade Required
- 449 Retry With
- 451Unavailable For Legal Reasons
- 服务器错误
- 500 Internal Server Error
- 501 Not Implemented
- 502 Bad Gateway
- 503 Service Unavailable
- 504 Gateway Timeout
- 505 HTTP Version Not Supported
- 506 Variant Also Negotiates
- 507 Insufficient Storage
- 509 Bandwidth Limit Exceeded
- 510 Not Extended
- 600 Unparseable Response Headers
- linux下自动执行任务
- restful api
- 富文本编辑器
- ueditor
- wangEditor
- js定时器
- 局域网访问本地项目
- 微信公众号网页授权登录
- 服务器配置https
- 配置虚拟目录
- ab压力测试
- 使用ab进行页面的压力测试
- apache性能测试工具ab使用详解
- 前后端分离之用户验证
- PHP面试题
- 题库一
- 题库二
- 题库三
- 题库四
- 题库五
- 题库六
- 算法题
- 星星算法
