FAQ 4 (with answers) and PHP with answers

Source: Internet
Author: User

FAQ 4 (with answers) and PHP with answers

1. echo count ("abcd"); how much is output?

Answer: 4

 

2. After running the following code $ a $ B $ c is?

<?php    $a=$b=$c=0;    $a=$b && $c;

Answer: false, 0, 0

 

4. Use the heredoc syntax format of php to output: hello world!

<?php      $v=”hello world”;      $str=<<<EOT      $vEOT;echo $str;

 

5. $ string = "abcdefg", what is the value of $ string {4?

Answer: e

 

6. Briefly describe the differences between echo (), print (), and print_r.

Answer:Echo ()Multiple values can be output at a time. Multiple values are separated by commas. Echo is a language structure rather than a real function. Therefore, it cannot be used as part of an expression.

Print ()Is a function used to print a value. If the string is successfully displayed, true is returned; otherwise, false is returned.

Print_r ()Is a function that is used to print a value. The value is a string or number for simple printing, while the Array is displayed in the form of an enclosed key and Value List and starts with an Array.

Extended: var_dump () is a function used to display the result information about one or more expressions, including the expression type and value. The array recursively expands the value and displays its structure through indentation.

 

7. Use PHP to write the code that shows the Client IP address and Server IP address.

Client IP: echo $ _ SERVER ['remote _ ADDR '];

Or echo getenv ('remote _ ADDR ');

Server ip: echo $ _ SERVER ['server _ ADDR '];

Or echo getenv ('server _ ADDR ');

 

8. Use a regular expression to determine whether $ a is a string consisting of multiple phone numbers separated by commas (,).

<?php      $math=“/((\d){11},)+/”;      $str=”12345678901,12345678901”;      if(preg_match($match,$str)){        echo ‘yes’;    }?>  

 

9. Define a class named MyClass. This class has only one static method, justDoIt.

class MyClass{      public static function justDoIt()      {      }}

 

11. Write out several design patterns you know and use php code to implement one.

Answer: single-State mode, factory mode, generator mode, proxy mode, and iteration mode. Examples of single-State mode: class test {private static $ obj = null; private function _ construct () {echo 'connect to database for the first time ';} public static function getInstance () {if (is_null (self ::$ obj) {self ::$ obj = new self (); return self: $ obj ;}}}

 

 

12. What functions will be affected by enabling Safe_mode in php. ini?

Answer: chown (), chgrp (), chdir (), fopen (), rmdir (), copy (), link (), exec ()

 

 

 

13. Describe the intention of the following URL rewriting rules.

<IfModule mod_rewrite.c>

RewriteEngine on

RewriteCond % {REQUEST_FILENAME }! -F

RewriteCond % {REQUEST_FILENAME }! -D

RewriteBase/

RewriteRule./index. php [L]

</IfModule>

Answer: forcibly resolve the URL address to./index. php.

 

14. Which function will you use to set the Content-Type of the current Content?

HeaderFunction

//Define Encoding

Header ("Content-type: text/html; charset = UTF-8 ");

// CSS

Header ("Content-type: text/css ");

// JavaScript

Header ("Content-type: text/javascript ");

// JPEG Image

Header ("Content-type: image/jpeg ");

// GIF Image

Header ("Content-type: image/gif ");

// PNG Image

Header ("Content-type: image/png ");

// JSON

Header ("Content-type: application/json ");

// PDF

Header ("Content-type: application/pdf ");

// XML

Header ("Content-type: text/xml ");

// OK

Header ("HTTP/1.1 200 OK ");

// 404Header

Header ('Http/1.1 404 Not Found ');

//Sets the address to be permanently redirected.

Header ('Http/1.1 301 Moved Permanently ');

//Go to a new address

Header ('Location: http://www.example.org /');

//File delay redirection

Header ('Refresh: 10; url = http://www.example.org /');

Print'You will be redirected in 10 seconds ';

//Plain text format

Header ('Content-type: text/plain ');

 

15. warning: Cannot modify header information-headers already sent by (output started at D: \ src \ init. php: 7) in D: \ src \ init. php on line 10 under what circumstances does php report this warning message?

Answer: Before the header ('content-type: text/html; charset = UTF-8 '), any output will produce the following error.

 

16. A enter the user name abc and password 123 on the page to log on to www.10086.cn. Please write the HTTP packet (including the request line, message header, and request body) of the request ).

Answer:

Post or login HTTP/1.1

================

Host: www.10086.cn

Content-Type: application/x-www-form-urlencoded

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: 1.7.6)

Content-length: 25

Refer: www.10086.cn

================

Username = abc & password = 123

 

17. Write a php code to traverse all the files and subfolders in a directory.

<?php      function scandir($path){        $files = array();        $handle = opendir($path);        if ($filename=@readdir($handle)) {            if ($filename==’.’ || $filename==’..’) {                continue;            }            if (is_dir($filename)){                $files[$filename] = scandir($path.’/’.$filename);       } else {            $files[$filename] = $filename;       }      }        return $files;   }?>

 

 

18. What is the linux Command for viewing disk space usage? Check which system processes are running commands? Which commands are used to monitor linux performance (cpu, disk I/O, memory, and network?

Answer: df, ps, top

 

19. What command is used to terminate a process in linux? What commands are used to package, compress, and uncompress? What is the command to establish a soft connection?

Answer:

Pkill-9Process name or kill process number,

Tar zcvfAnd tar zxvf

Ln

 

20. How can I implement the script five. php every five minutes?

Answer: crontab-e

*/5 * php five. php

 

21. What is the maximum length of varchar in mysql? What types of fields are used to store large text? What is the difference between date and datetime and timestamp? What are the SQL statements in the database?

Answer:

65535,

Text,

Differences:

1.Different buckets

A) TIMESTAMP4 bytes

B) DATETIMETakes 8 bytes

2.Affected by Time Zone

A) TIMESTAMPThe actual number of records is 00:00:01 to the present, affected by the time zone

B) DATETIMENot Affected by Time Zone

3.Different time ranges

A) TIMESTAMPThe time range is: '2017-01-01 00:00:01 'UTC ~ '2017-01-19 03:14:07 'UTC

B) DATETIMEThe time range is: '2017-01-01 00:00:00 '~ '2017-12-31 23:59:59'

4.Automatic update

TIMESTAMPBy default, when data is inserted or updated, the TIMESTAMP column is automatically filled/updated with the current time (CURRENT_TIMESTAMP.

 

Show processlist;

 

22. A MySQL database table: User

Name Tel Content Date

Zhang San 13333663366 graduated from college-10-11

Michael Zhang graduated from 13612312331 undergraduate course-10-15

Zhang Si 021-55665566 graduated from technical secondary school 2006-10-15

 

Write the following SQL statement:

(A) There is a new record (Mr. Wang graduated from high school 13254748547-). Please use SQL statements to add it to the table.

(B) use SQL statements to update Michael's time to the current system time.

(C) Please write out all records named zhangsi.

Answer:

(A) inser into User (Name, Tel, Content, Date) values ("Mr. Wang ", 12354748547," high school graduation ");

(B) update User set Date = date (now () where User ="James ";

(C) delete from User where User ="James ";

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.