1、抓取远程图片到本地,你会用什么函数?
fsockopen, a
2、用最少的代码写一个求3值最大值的函数.
function($a,$b,$c){
* w0 z* u6 k+ e. l a: }5 } return $a>$b? ($a>$c? $a : $c) : ($b>$c? $b : $c );
5 o: f6 v1 w# u}
3、用php打印出前一天的时间,打印格式是2007年5月10日22:21:21
echo date(‘y-m-d h:i:s’,strtotime(‘-1 day’));
4、javascript能否定义二维数组,如果不能你如何解决?
javascript不支持二维数组定义,可以用arr[0] = new array()来解决
5、假设a.html和b.html在同一个文件夹下面,用javascript实现当打开a.html五秒钟后,自动跳转到b.html。
function go2b(){
window.location = “b.html”;
window.close();
}
settimeout( “go2b()”,5000 ); //5秒钟后自动执行go2b()
6、//正在浏览当前页面用户的 ip 地址:127.0.0.1
echo $_server["remote_addr"].”
”;
//查询(query)的字符串(url 中第一个问号 ? 之后的内容):id=1&bi=2
echo $_server["query_string"].”
”;
//当前运行脚本所在的文档根目录:d:inetpubwwwroot
echo $_server["document_root"].”
”;
7、在http 1.0中,状态码 401 的含义是未授权____;如果返回“找不到文件”的提示,则可用 header 函数,其语句为header(“http/1.0 404 not found”);
答:401表示未授权;header(“http/1.0 404 not found”);
8、写一个函数,能够遍历一个文件夹下的所有文件和子文件夹。
function my_scandir($dir)
{
$files=array();
if(is_dir($dir))
{
if($handle=opendir($dir))
{
while(($file=readdir($handle))!==false)
{
if($file!=”.” && $file!=”..”)
{
if(is_dir($dir.”/”.$file))
{
$files[$file]=my_scandir($dir.”/”.$file);
}
else
{
$files[]=$dir.”/”.$file;
}
}
}
closedir($handle);
return $files;
}
}
}
print_r(my_scandir(“d:program filesinternet explorermui”));
?>
9、把 john 新增到 users 阵列?
$users[] = ‘john’; array_push($users,‘john’);
10、在php中error_reporting这个函数有什么作用?
答:error_reporting() 设置 php 的报错级别并返回当前级别。
11、请用正则表达式(regular expression)写一个函数验证电子邮件的格式是否正确。
答:
$email=$_post['email'];
if(!preg_match(‘/^[\w.]+@([\w.]+)\.[a-z]{2,6}$/i’,$email)) {
echo “电子邮件检测失败”;
}else{
echo “电子邮件检测成功”;
}
?>
12、用php写出显示客户端ip与服务器ip的代码
答:打印客户端ip:echo $_server[‘remote_addr’]; 或者: getenv(‘remote_addr’);
打印服务器ip:echo gethostbyname(“www.bolaiwu.com”)
13、如何修改session的生存时间(1分).
答:方法1:将php.ini中的session.gc_maxlifetime设置为9999重启apache
方法2:$savepath = “./session_save_dir/”;
$lifetime = 小时 * 秒;
session_save_path($savepath);
session_set_cookie_params($lifetime);
session_start();
方法3:setcookie() and session_set_cookie_params($lifetime);
14、有一个网页地址, 比如php开发资源网主页: http://www.phpres.com/index.html,如何得到它的内容?($1分)
答:方法1(对于php5及更高版本):
$readcontents = fopen(“http://www.phpres.com/index.html”, “rb”);
$contents = stream_get_contents($readcontents);
fclose($readcontents);
echo $contents;
方法2:
echo file_get_contents(“http://www.phpres.com/index.html”);
15、请说明php中传值与传引用的区别。什么时候传值什么时候传引用?(2分)
答:按值传递:函数范围内对值的任何改变在函数外部都会被忽略
按引用传递:函数范围内对值的任何改变在函数外部也能反映出这些修改
优缺点:按值传递时,php必须复制值。特别是对于大型的字符串和对象来说,这将会是一个代价很大的操作。
按引用传递则不需要复制值,对于性能提高很有好处。
16、写一个函数,尽可能高效的,从一个标准 url 里取出文件的扩展名
例如: http://www.sina.com.cn/abc/de/fg.php?id=1 需要取出 php 或 .php
答案1:
function getext($url){
$arr = parse_url($url);
$file = basename($arr['path']);
$ext = explode(“.”,$file);
return $ext[1];
}
答案2:
function getext($url) {
$url = basename($url);
$pos1 = strpos($url,”.”);
$pos2 = strpos($url,”?”);
if(strstr($url,”?”)){
return substr($url,$pos1 + 1,$pos2 – $pos1 – 1);
} else {
return substr($url,$pos1);
}
}
17、使用五种以上方式获取一个文件的扩展名
要求:dir/upload.image.jpg,找出 .jpg 或者 jpg ,
必须使用php自带的处理函数进行处理,方法不能明显重复,可以封装成函数,比如 get_ext1($file_name), get_ext2($file_name)
function get_ext1($file_name){
return strrchr($file_name, ‘.’);
}
function get_ext2($file_name){
return substr($file_name, strrpos($file_name, ‘.’));
}
function get_ext3($file_name){
return array_pop(explode(‘.’, $file_name));
}
function get_ext4($file_name){
$p = pathinfo($file_name);
return $p['extension'];
}
function get_ext5($file_name){
return strrev(substr(strrev($file_name), 0, strpos(strrev($file_name), ‘.’)));
}
18、$str1 = null;
$str2 = false;
echo $str1==$str2 ? ‘相等’ : ‘不相等’;
$str3 = ”;
$str4 = 0;
echo $str3==$str4 ? ‘相等’ : ‘不相等’;
$str5 = 0;
$str6 = ’0′;
echo $str5===$str6 ? ‘相等’ : ‘不相等’;
?>
相等 相等 不相等
19、mysql数据库中的字段类型varchar和char的主要区别是什么?那种字段的查找效率要高,为什么?
varchar是变长,节省存储空间,char是固定长度。查找效率要char型快,因为varchar是非定长,必须先查找长度,然后进行数据的提取,比char定长类型多了一个步骤,所以效率低一些
20、请使用javascript写出三种产生一个image 标签的方法(提示:从方法、对象、html角度考虑)
(1)var img = new image();
(2)var img = document.createelementbyid(“image”)
(3)img.innerhtml = “”
21、16.请描述出两点以上xhtml和html最显著的区别
(1)xhtml必须强制指定文档类型doctype,html不需要
(2)xhtml所有标签必须闭合,html比较随意
22、写一个排序算法,可以是冒泡排序或者是快速排序,假设待排序对象是一个维数组。
//冒泡排序(数组排序)
function bubble_sort($array)
{
$count = count($array);
if ($count for($i=0; $ifor($j=$count-1; $j>$i; $j–){
if ($array[$j] $tmp = $array[$j];
$array[$j] = $array[$j-1];
$array[$j-1] = $tmp;
}
}
}
return $array;
}
//快速排序(数组排序)
function quicksort($array) {
if (count($array) $key = $array[0];
$left_arr = array();
$right_arr = array();
for ($i=1; $i
else
$right_arr[] = $array[$i];
}
$left_arr = quicksort($left_arr);
$right_arr = quicksort($right_arr);
return array_merge($left_arr, array($key), $right_arr);
}
23、写出三种以上mysql数据库存储引擎的名称(提示:不区分大小写)
myisam、innodb、bdb(berkeley db)、merge、memory(heap)、example、federated、archive、csv、blackhole、maxdb 等等十几个引擎
24、求两个日期的差数,例如2007-2-5 ~ 2007-3-6 的日期差数
方法一:
class dtime
{
function get_days($date1, $date2)
{
$time1 = strtotime($date1);
$time2 = strtotime($date2);
return ($time2-$time1)/86400;
}
}
$dtime = new dtime;
echo $dtime->get_days(’2007-2-5′, ’2007-3-6′);
?>
方法二:
$temp = explode(‘-’, ’2007-2-5′);
$time1 = mktime(0, 0, 0, $temp[1], $temp[2], $temp[0]);
$temp = explode(‘-’, ’2007-3-6′);
$time2 = mktime(0, 0, 0, $temp[1], $temp[2], $temp[0]);
echo ($time2-$time1)/86400;
方法三:echo abs(strtotime(“2007-2-1′)-strtotime(“2007-3-1′))/60/60/24 计算时间差
25、请写一个函数,实现以下功能:
字符串“open_door” 转换成 “opendoor”、”make_by_id” 转换成 ”makebyid”。
方法:
function str_explode($str){
$str_arr=explode(“_”,$str);$str_implode=implode(” “,$str_arr); $str_implode=implode
(“”,explode(” “,ucwords($str_implode)));
return $str_implode;
}
$strexplode=str_explode(“make_by_id”);print_r($strexplode);
方法二:$str=”make_by_id!”;
$expstr=explode(“_”,$str);
for($i=0;$i
echo ucwords($expstr[$i]);
}方法三:echo str_replace(‘ ‘,”,ucwords(str_replace(‘_’,’ ‘,’open_door’)));
26、一个表中的id有多个记录,把所有这个id的记录查出来,并显示共有多少条记录数,用sql语句及视图、
存储过程分别实现。
delimiter //
create procedure proc_countnum(in columnid int,out rowsno int)
begin
select count(*) into rowsno from member where member_id=columnid;
end
call proc_countnum(1,@no);
select @no;
方法:视图:
create view v_countnum as select member_id,count(*) as countnum from member group by
member_id
select countnum from v_countnum where member_id=1
27、js中网页前进和后退的代码 ( 前进: history.forward();=history.go(1); 后退: history.back
();=history.go(-1); )
28、echo count(“abc”); 输出什么?
答案:1
count — 计算数组中的单元数目或对象中的属性个数
int count ( mixed$var [, int $mode ] ), 如果 var 不是数组类型或者实现了 countable 接口的对象,将返回1,有一个例外,如果 var 是 null 则结果是 0。
对于对象,如果安装了 spl,可以通过实现 countable 接口来调用 count()。该接口只有一个方法 count(),此方法返回 count() 函数的返回值。
29、有一个一维数组,里面存储整形数据,请写一个函数,将他们按从大到小的顺序排列。要求执行效率高。并说明如何改善执行效率。(该函数必须自己实现,不能使用php函数)
function bubblesort(&$arr)
{
$cnt=count($arr);
$flag=1;
for($i=0;$i{
if($flag==0)
{
return;
}
$flag=0;
for($j=0;$j{
if($arr[$j]>$arr[$j+1])
{
$tmp=$arr[$j];
$arr[$j]=$arr[$j+1];
$arr[$j+1]=$tmp;
$flag=1;
}
}
}
}
$test=array(1,3,6,8,2,7);
bubblesort($test);
var_dump($test);
?>
30、请举例说明在你的开发过程中用什么方法来加快页面的加载速度
答:要用到服务器资源时才打开,及时关闭服务器资源,数据库添加索引,页面可生成静态,图片等大文件单独服务器。使用代码优化工具
31、.以下的代码会产生什么?为什么?
$num =10;
function multiply(){
$num =$num *10;
}
multiply();
echo $num;
由于函式 multiply() 没有指定 $num 为全域变量(例如 global $num 或者 $_globals['num']),所以 $num 的值是 10。
32. php class中static,public,private,protected的区别?
static 静态,类名可以访问
public 表示全局,类内部外部子类都可以访问;
private表示私有的,只有本类内部可以使用;
protected表示受保护的,只有本类或子类或父类中可以访问;
33. http协议中get、post和head的区别?
head: 只请求页面的首部。
get: 请求指定的页面信息,并返回实体主体。
post: 请求服务器接受所指定的文档作为对所标识的uri的新的从属实体。
(1)http 定义了与服务器交互的不同方法,最基本的方法是 get 和 post。事实上 get 适用于多数请求,而保留 post 仅用于更新站点。
(2)在form提交的时候,如果不指定method,则默认为get请 求,form中提交的数据将会附加在url之后,以?分开与url分开。字母数字字符原样发送,但空格转换为“+“号,其它符号转换为%xx,其中xx为 该符号以16进制表示的ascii(或iso latin-1)值。get请求请提交的数据放置在http请求协议头中,而post提交的数据则放在实体数据中;
get方式提交的数据最多只能有1024字节,而post则没有此限制。
(3)get 这个是浏览器用语向服务器请求最常用的方法。post这个方法也是用来传送数据的,但是与get不同的是,使用post的时候,数据不是附在uri后面传递的,而是要做为独立的行来传递,此时还必须要发送一个content_length标题,以标明数据长度,随后一个空白行,然后就是实际传送的数据。网页的表单通常是用post来传送的。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号