php笔试(一)

Jun 23, 2016 pm 02:34 PM

1.$array['anykey']和$array[anykey]的区别?

答:单引号和没有单引号区别,就是字符串和常量。而单引号和双引号的区别,就是字符串和变量吧。
      不加单引号的话,php会首先认为他是常量,然后去搜寻是否存在这个常量,若不存在,则理解为字符串,所以在效率上就慢了。

2.echo 输出语句时候的连接符号: "." 和 ","。点号和逗号的区别?

 

答:echo用点号时先把语句连接再输出,而用逗号就等于给它传多个参数,不需要进行字符串拼接这一步,效率高! // 本文来自技术世界www.js4j.com 技术教程//

3.echo,print,print_r的区别?

答:echo,直接输出单个或者多个字符串,是PHP语句!
      print,打印输出简单类型,是PHP函数!有整型返回值。我试验了下,都返回1。
      print_r,格式化打印输出,常用于比较复杂的类型,如数组,对象之类的,可以输出完整结构,是PHP函数,返回值类型为布尔型!

 

4.获取前天的日期,格式如:2009-01-12 17:15:20

 

答:echo date('Y-m-d h:i:s',time()-2*24*60*60);
      echo date('Y-m-d h:i:s',strtotime('2 days ago')); 未来几天的话把 ago 去掉就行了 // 来自www.js4j.com 技术BBS论坛//

5.如何将字符串翻转过来?

 

答:$str = '7654321';
      echo strrev($str); //1234567
      另一种方法:
      $strlen = strlen($str);
      for ($i = 1; $i          echo substr($str,-$i,1);
      } // 内容来自js4j.com//

6.优化MySQL数据库的方法?

 

答:①选取最适用的字段属性。
      ②是用连接(JOIN)来代替子查询(Sub-Queries)。
      ③是用联合(UNION)来代替手动创建的临时表。
      ④事务
      ⑤锁定表
      ⑥使用外键
      ⑦使用索引
      ⑧优化的查询语句
      上面8条优化的详细说明请点击该链接查看完全优化MySQL数据库性能的八大巧方法

 

7.PHP的意思?(送一分)

 

答:Hypertext preprocessor 超文本预处理语言。(汗!我google了才知道滴。。送一分都得不到啊,撞墙!!)

 

8.MYSQL取得当前时间的函数是?格式化日期的函数是?

 

答:当前日期函数为 NOW();
      格式化日期函数是:
         SELECT DATE_FORMAT('2009-01-11 17:25:36',"%H:%i:%s %m/%d/%Y"); 
        ->17:25:36 01/11/2009

         其它时间函数:详细请查看该页面 MySql 格式化时间函数
        SELECT DAYOFWEEK('1998-02-03');
        ->3

         SELECT WEEKDAY('1997-10-04 22:23:00');
        ->5
        SELECT WEEKDAY('1997-11-05');
        ->2

         SELECT DAYOFMONTH('1998-02-03');
        ->3

         SELECT DAYOFYEAR('1998-02-03');


        ->34

        SELECT MONTH('1998-02-03');
        ->2

         SELECT DAYNAME('1998-02-05');
        ->'February'

         SELECT QUARTER('1998-04-01');
        ->2
        
        SELECT WEEK('1998-02-20');
        ->7
         SELECT WEEK('1998-02-20',0);
        ->7
        SELECT WEEK('1998-02-20',1);
        ->8

         SELECT YEAR('98-02-03'); 
        ->1998

        SELECT HOUR('10:05:03');
        ->10

        SELECT MINUTE('98-02-03 10:05:03');
        ->5

        SELECT SECOND('10:05:03');
        ->3

        SELECT PERIOD_ADD(9801,2);
        ->199803

         SELECT PERIOD_DIFF(9802,199703);
        ->11

        SELECT TO_DAYS('1997-10-07');
         ->729669
        SELECT TO_DAYS(950501); 
        ->728779

        SELECT FROM_DAYS(729669);
        ->'1997-10-07'

        SELECT UNIX_TIMESTAMP('1997-10-04 22:23:00');
        ->875996580

         SELECT FROM_UNIXTIME(875996580);
        ->'1997-10-04 22:23:00'

         SELECT SEC_TO_TIME(2378);
         ->00:39:38

         SELECT TIME_TO_SEC('00:39:38');
        ->2378 // 本文来自技术世界www.js4j.com 技术教程//

 

9.怎样截取中文且不出现乱码?

 

答:如果安装了mb扩展可使用mb_substr();
      可以使用以下函数:
         function cutstr($sourcestr, $startlength, $cutlength) 
         { 
            $returnstr=''; 
            $i=0; 
            $n=0; 
            $str_length=strlen($sourcestr);             //字符串的字节数 
            while (($n            { 
               $temp_str=substr($sourcestr,$i,1); // 内容来自js4j.com// 
               $ascnum=Ord($temp_str);                //得到字符串中第$i位字符的ascii码 
               if ($ascnum>=224) {                  //如果ASCII位高与224,
                  $returnstr=$returnstr.substr($sourcestr,$i,3); //根据UTF-8编码规范,将3个连续的字符计为单个字符         
                  $i=$i+3;                            //实际Byte计为3


                  $n++;                            //字串长度计1
               } elseif ($ascnum>=192){               //如果ASCII位高与192,
                  $returnstr=$returnstr.substr($sourcestr,$i,2); //根据UTF-8编码规范,将2个连续的字符计为单个字符 
                  $i=$i+2;                            //实际Byte计为2
                  $n++;                             //字串长度计1 // 来自www.js4j.com 技术BBS论坛// 
               } elseif ($ascnum>=65 && $ascnum                  $returnstr=$returnstr.substr($sourcestr,$i,1); 
                  $i=$i+1;                            //实际的Byte数仍计1个
                  $n++;                             //但考虑整体美观,大写字母计成一个高位字符
               } else {                               //其他情况下,包括小写字母和半角标点符号, // 内容来自技术世界www.js4j.com 技术爱好者// 
                  $returnstr=$returnstr.substr($sourcestr,$i,1); 
                  $i=$i+1;                            //实际的Byte数计1个
                  $n=$n+0.5;                         //小写字母和半角标点等与半个高位字符宽...
               } 
      
             if ($n               $returnstr = ''; 
              continue;
             }
             }
    
             if ($str_length>$cutlength){
                $returnstr = $returnstr . "...";           //超过长度时在尾处加上省略号
             }
             return $returnstr; 
         }

 

10.对于大流量的网站,您采用什么样的方法来解决访问量问题?

 

答:①最根本的是服务器硬件条件。服务器硬件设备如果太差,那不管怎么优化都是徒劳!
      ②对数据库进行优化。主要是减少对数据库的访问量。访问过多会造成服务器CPU过度消耗,导致服务器受访能力严重下降,解决方法是是前台使用静态或者动态缓存!
      ③防盗链。对于Apache服务器,主要是是用model_rewrite 模块通过对URL的正则,进行限制和重定向!
      ④控制大文件下载。不提供超过2MB的文件下载,或使用专门的下载服务器,或者上传到web2.0共享网站上。
      ⑤多主机分流。将不同文件放置在不同的主机,提供镜像之类的文件下载方式。 
      ⑥是用专业的流量分析软件。如google流量分析。对网站进行精细的流量控制!

 

11.用PHP写出显示客户端IP与服务器IP的代码? // 本文来自技术世界www.js4j.com 专业技术门户网站//

答:客户端IP获取 $_SERVER['REMOTE_ADDR'];  
      服务端IP获取 $_SERVER['SERVER_NAME'];

 

12.如何修改SESSION的生存时间?

答:$lifeTime = 24*3600;
      session_set_cookie_params($lifeTime);
       session_start();
详细的设置请查看这篇文章:PHP对session生存时间的设置详细介绍。

 

13.有一个网页地址, 比如PHP研究室主页: http://www.163fly.com/index.php如何得到它的内容?

 

答:$src = 'http://www.163fly.com/index.php';
       $file = 'D:\index.html';

       ①$content = file_get_contents($src);
         $hfile = fopen($file,w);
         $result = fwrite($hfile,$content);

      ②$opsrc = fopen($src,r);
          $wfile = fopen($file,w);
         $result = stream_copy_to_stream($opsrc,$wfile);

 

14.在HTTP 1.0中,状态码401的含义是?;如果返回“找不到文件”的提示,则可用 header 函数,其语句为?

答:①HTTP/1.0 401 代表:未授权。 ②可用 header("HTTP/1.0 404 Not Found");

 

15.在PHP中,heredoc是一种特殊的字符串,它的结束标志必须?

 

答:          ......
标识符;
       结束标识符前不能有任何其它字符!

 

 

找工作中常见的PHP面试题及答案

http://www.js4j.com/tech/php/467.html

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

How does PHP type hinting work, including scalar types, return types, union types, and nullable types? How does PHP type hinting work, including scalar types, return types, union types, and nullable types? Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

See all articles