php面试题
时间:2008-02-27 来源:octans
1、用PHP打印出前一天的时间格式是2006-5-10 22:21:21
echo date('Y-m-d H:i:s', strtotime('-1 day'));
strtotime — 将任何英文文本的日期时间描述解析为 Unix 时间戳
2、echo(),print(),print_r()的区别
echo()是语句结构,不是函数;print()也是语句结构,但它有返回值。
?php
$b ? print 'true' : print 'false';//ok
$b ? echo 'true' : echo 'false';//wrong
?>
echo在不使用括号时,可以有多个参数;而print在不使用小括号时只能有一个参数
echo "and a ", 1, 2, 3; // comma-separated without parentheses
echo ("and a 123"); // just one parameter with parentheses
print ("and a 123");
print "and a 123";//can only take one parameter:
print_r()可以打印出更详细的信息,尤其是数组和对象。
来自:
http://www.phpx.com/viewarticle.php?id=119919
3、使用哪些工具进行版本控制?
CVS,Concurrent Versions System的缩写,支持多种操作系统,开源软件,C/S结构。
VSS, 微软产品,只可用于windows系统
来自:
http://www.91php.cn/rewrite.php/read-171.html
4、如何实现字符串翻转?
使用php自带函数strrev()
?php
echo strrev("Hello world!"); // outputs "!dlrow olleH"
?>
自己写
function strrev($str)
{
$len = strlen($str);
$newStr = '';
for($i = $len; $i >= 0; $i--)
{
$newstr .= $str{$i};
}
return $newstr;
}
5、优化MYSQL数据库的方法
?
6、apache+mysql+php实现最大负载的方法
?
7、实现中文字串截取无乱码的方法
mb_substr() 需要安装mb扩展
8.某内容管理系统中
(1)表message有如下字段
id 文章id
title 文章标题
content 文章内容
category_id 文章分类id
hits 点击量
创建上表,写出MySQL语句
DROP TABLE IF EXISTS `message`;
CREATE TABLE `message`(
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`title` VARCHAR(50) NOT NULL,
`content` TEXT DEFAULT NULL,
`hits` INT(5) UNSIGNED DEFAULT '0',
PRIMARY KEY (`id`)
)ENGINE=MYISAM DEFAULT CHARSET=utf8;
INSERT INTO `message`(`title`, `content`, `hits`)VALUES
('tilte1', 'content1', '1'),
('title2', 'content2', '2'),
('title3', 'content3', '3'),
('title4', 'content4', '4'),
('title5', 'content5', '5');
(2)表comment记录用户回复内容,字段如下
comment_id 回复id
id 文章id,关联message表中的id
comment_content 回复内容
DROP TABLE IF EXISTS `comment`;
CREATE TABLE `comment`(
`comment_id` INT(15) UNSIGNED NOT NULL AUTO_INCREMENT,
`comment_content` TEXT DEFAULT NULL,
`id` INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (`comment_id`),
FOREIGN KEY (`id`) REFERENCES `message`
)ENGINE=MYISAM DEFAULT CHARSET=UTF8;
INSERT INTO `comment`(`comment_content`, `id`)VALUES
('comment_content1', '1'),
('comment_content2', '1'),
('comment_content3', '2'),
('comment_content4', '2'),
('comment_content5', '2'),
('comment_content6', '3'),
('comment_content7', '4'),
('comment_content8', '5');
现通过查询数据库需要得到以下格式的文章标题列表,并按照回复数量排序,回复最高的排在最前面
文章id 文章标题 点击量 回复数量
用一个SQL语句完成上述查询,如果文章没有回复则回复数量显示为0 ?
SELECT `message`.`id`, `message`.`title`, `message`.`hits`, COUNT( `comment`.`comment_id`)
FROM `message`, `comment`
WHERE `comment`.`id` = `message`.`id`
GROUP BY `message`.`id`
ORDER BY COUNT( `comment`.`comment_id` )DESC;
这样做,不符合“如果文章没有回复则回复数量显示为0”的要求
SELECT `message`.`id`, `message`.`title`, `message`.`hits`,(SELECT COUNT(*) FROM comment WHERE comment.id = message.id) AS `comment_no`
FROM `message`
ORDER BY `comment_no` DESC;
这样就ok了,感谢phpchina上的mysql斑竹coolstr
http://bbs.phpchina.com/thread-52927-1-1.html
(3)上述内容管理系统,表category保存分类信息,字段如下
category_id int(4) not null auto_increment;
categroy_name varchar(40) not null;
用户输入文章时,通过选择下拉菜单选定文章分类
写出如何实现这个下拉菜单
来自:
http://www.hackhome.com/html/jskf/phpwz/2006/0808/50653.html
echo date('Y-m-d H:i:s', strtotime('-1 day'));
strtotime — 将任何英文文本的日期时间描述解析为 Unix 时间戳
2、echo(),print(),print_r()的区别
echo()是语句结构,不是函数;print()也是语句结构,但它有返回值。
?php
$b ? print 'true' : print 'false';//ok
$b ? echo 'true' : echo 'false';//wrong
?>
echo在不使用括号时,可以有多个参数;而print在不使用小括号时只能有一个参数
echo "and a ", 1, 2, 3; // comma-separated without parentheses
echo ("and a 123"); // just one parameter with parentheses
print ("and a 123");
print "and a 123";//can only take one parameter:
print_r()可以打印出更详细的信息,尤其是数组和对象。
来自:
http://www.phpx.com/viewarticle.php?id=119919
3、使用哪些工具进行版本控制?
CVS,Concurrent Versions System的缩写,支持多种操作系统,开源软件,C/S结构。
VSS, 微软产品,只可用于windows系统
来自:
http://www.91php.cn/rewrite.php/read-171.html
4、如何实现字符串翻转?
使用php自带函数strrev()
?php
echo strrev("Hello world!"); // outputs "!dlrow olleH"
?>
自己写
function strrev($str)
{
$len = strlen($str);
$newStr = '';
for($i = $len; $i >= 0; $i--)
{
$newstr .= $str{$i};
}
return $newstr;
}
5、优化MYSQL数据库的方法
?
6、apache+mysql+php实现最大负载的方法
?
7、实现中文字串截取无乱码的方法
mb_substr() 需要安装mb扩展
8.某内容管理系统中
(1)表message有如下字段
id 文章id
title 文章标题
content 文章内容
category_id 文章分类id
hits 点击量
创建上表,写出MySQL语句
DROP TABLE IF EXISTS `message`;
CREATE TABLE `message`(
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`title` VARCHAR(50) NOT NULL,
`content` TEXT DEFAULT NULL,
`hits` INT(5) UNSIGNED DEFAULT '0',
PRIMARY KEY (`id`)
)ENGINE=MYISAM DEFAULT CHARSET=utf8;
INSERT INTO `message`(`title`, `content`, `hits`)VALUES
('tilte1', 'content1', '1'),
('title2', 'content2', '2'),
('title3', 'content3', '3'),
('title4', 'content4', '4'),
('title5', 'content5', '5');
(2)表comment记录用户回复内容,字段如下
comment_id 回复id
id 文章id,关联message表中的id
comment_content 回复内容
DROP TABLE IF EXISTS `comment`;
CREATE TABLE `comment`(
`comment_id` INT(15) UNSIGNED NOT NULL AUTO_INCREMENT,
`comment_content` TEXT DEFAULT NULL,
`id` INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (`comment_id`),
FOREIGN KEY (`id`) REFERENCES `message`
)ENGINE=MYISAM DEFAULT CHARSET=UTF8;
INSERT INTO `comment`(`comment_content`, `id`)VALUES
('comment_content1', '1'),
('comment_content2', '1'),
('comment_content3', '2'),
('comment_content4', '2'),
('comment_content5', '2'),
('comment_content6', '3'),
('comment_content7', '4'),
('comment_content8', '5');
现通过查询数据库需要得到以下格式的文章标题列表,并按照回复数量排序,回复最高的排在最前面
文章id 文章标题 点击量 回复数量
用一个SQL语句完成上述查询,如果文章没有回复则回复数量显示为0 ?
SELECT `message`.`id`, `message`.`title`, `message`.`hits`, COUNT( `comment`.`comment_id`)
FROM `message`, `comment`
WHERE `comment`.`id` = `message`.`id`
GROUP BY `message`.`id`
ORDER BY COUNT( `comment`.`comment_id` )DESC;
这样做,不符合“如果文章没有回复则回复数量显示为0”的要求
SELECT `message`.`id`, `message`.`title`, `message`.`hits`,(SELECT COUNT(*) FROM comment WHERE comment.id = message.id) AS `comment_no`
FROM `message`
ORDER BY `comment_no` DESC;
这样就ok了,感谢phpchina上的mysql斑竹coolstr
http://bbs.phpchina.com/thread-52927-1-1.html
(3)上述内容管理系统,表category保存分类信息,字段如下
category_id int(4) not null auto_increment;
categroy_name varchar(40) not null;
用户输入文章时,通过选择下拉菜单选定文章分类
写出如何实现这个下拉菜单
来自:
http://www.hackhome.com/html/jskf/phpwz/2006/0808/50653.html
相关阅读 更多 +
排行榜 更多 +