当前位置:文档之家› PHP面试题目

PHP面试题目

“中欧商业在线”PHP笔试
一、编程题
1、如何实现字符串翻转?(PHP)
答:可以用下面这个自定义函数
function getStr($str){ //输入字符串
$len=strlen($str); //计算字符串长度
for ($i=0;$i<$len/2;$i++){
$temp=$str[$i];
$str[$i]=$str[$len-$i-1];
$str[$len-$i-1]=$temp;
}
return $str; //返回翻转结果
}
2、解释这则用JS写得正则表达式。

/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
答:匹配以数字字母开头不能出现-+.,必需有一个@,再以数字字母开始,不能有-+.,只能有一个点,以字母结尾
3、用PHP写一个程序连接MYSQL数据库,并查出
<?php
$conn = mysql_connect('localhost','root','') or die ("连接MySql数据库失败,请稍后再试!");
$query = mysql_select_db('db',$conn) or die ("连接留言数据库失败!");
mysql_query("SET NAMES 'GBK'");
$sql = mysql_query(“select title from user;”);
$result = Mysql_fetch_array($sql);
Echo $resul[‘title’];
?>
4、DIV+CSS布局
首页
由于时间关系!布局没有做完。

5、用任何语言写一个排序函数
答:function getrange($a,$b) //假如传进来的是数字或字母
{
//按数字升序排序
$num1=array($a,,$b);
sort($num1,SORT_NUMERIC);
foreach ($num1 as $mychrs1)
{
echo $mychrs1." ";
}
//按字符升序排序
$num2=array($a,,$b);
sort($num2,SORT_STRING);
foreach ($num2 as $mychrs2)
{
echo $mychrs2." ";
}
}
二、概念题
6、数据库中的事务是什么
答:数据库事务是指作为单个逻辑工作单元执行的一系列操作。

7、你如何利用 PHP 解决 HTTP 的无状态本质?
答:最主要的的是选择session与cookie,使用session的方法是在每一页的开始加上sesseion_start(),然后利用$_session散列表来储存session变量,cookie原则是,在输出任何文字调用之前调用set_cookie()函数,此外只需要用$_cookie散列表便可以存取所有cookie变量了。

8、写出你最做过的项目的目录编排结构(PHP\.NET\JAVA 都可)
答:就以我提交的作品说吧!
目录分为:数据操作(data),文章(article),软件(soft),电影(movie),公共图片夹(image),布局(CSS),模板(template),常用的函数(inc),访客(guest),后台管理(webadmin),再加上首页要用在文件放在根目录。

三、英语阅读
9、阅读下面一段话,说出大致的意思
Script overview
The cron.php script looks through the mdl_modules table (assuming the default table prefix is mdl_) in the Moodle database for modules scheduled to have their cron functions run; it then looks in each such module directory for a function called module-name_cron in the lib.php file and runs it. It also looks through the mdl_block table for blocks scheduled for their cron methods (object functions) to be run; it then, for each such block, runs the cron method for a new object associated with that block (I'm omitting details for the benefit of non-programmers; programmers can read admin/cron.php for themselves). These files (the lib.php files and the files where the block classes are defined) can contain cleanup functions, email functions or anything that needs to be run on a regular basis. For example, cron will trigger the system to create the backups of courses at the time specified in the administration settings. It also triggers any messaging module or forum email notifications, but not all functions are called each time the cron runs. Some functions, such as unenrolling students who have not logged in or deleting old copies of log files, are only run occasionally. The cron.php file has a section which will randomly call these core tasks approximately 1 in 5 times the cron runs.
水平不好,简单的翻译了下:
cron.php脚本的通过调用mdl_modules表(假设默认表前缀mdl_)主,在为他们的CRON Moodle的功能模块数据库,然后在每个这样的一个功能模块目录看起来称为模块在name_cron lib.php文件并运行它。


也期待通过为他们的CRON方法(对象的功能)定期块mdl_block表运行,它然后,对于每个这种块,运行与该块相关联的新对象的cron方法(我省略的细节方便非程序员,程序员可以读取管理员/自己cron.php)。

这些文件(lib.php文件和文件,其中块类定义)可以包含清理功能,电子邮件功能或任何需要定期运行。

例如,cron将会触发系统创建行政部门在指定的时间设置的课程备份。

它也引发任何消息的模块或论坛的电子邮件通知,但并非所有的功能被称为每次cron会。

例如谁并没有或删除旧的日志文件的副本记录unenrolling一些学生的职能,只是偶尔运行。

该cron.php文件有一节,将随机调用这些核心任务约1 5倍的cron运行。

相关主题