PHP interview questions and answer 2

Source: Internet
Author: User
URL of the previous page linked to the current page

1. in PHP, the name of the current script (excluding the path and query string) is recorded in the predefined variable (1; the URL of the previous page linked to the current page is recorded in the predefined variable (2 ).

// This page address, SCRIPT_NAME can also be: php/test. php
Echo $ _ SERVER ['php _ SELF ']."
";
// URL of the previous page linked to the current page:
Echo $ _ SERVER ['http _ referer']."
";

// For other pre-defined variables, see Reference Manual: language reference variables.
// The absolute path name of the script before execution: D: Inetpubwwwrootphp est. php
Echo $ _ SERVER ["SCRIPT_FILENAME"]."
";
// Browsing the IP address of the user on the current page: 127.0.0.1
Echo $ _ SERVER ["REMOTE_ADDR"]."
";
// Query string (the first question mark in the URL? ): Id = 1 & bi = 2
Echo $ _ SERVER ["QUERY_STRING"]."
";
// The root directory of the file where the script is currently running: d: inetpubwwwroot
Echo $ _ SERVER ["DOCUMENT_ROOT"]."
";
?>

2. Execution section Output __.

// Reference Manual language reference operator arithmetic operator % is a modulo operation and outputs 0
Echo 8% (-2 )."
";
// The result of modulo $ a % $ B when $ a is a negative value is also a negative value. Output-2
Echo (-8) % 3 )."
";
// Output 2
Echo (8% (-3 ))."
";
?>

3. in HTTP 1.0, status code 401 indicates ____. if the "File Not Found" prompt is returned, the header function is available, and its statement is ____.

A: "401" indicates that authorization is Not performed. header ("HTTP/1.0 404 Not Found"). [refer to "Reference Manual"> "function reference"> "HTTP function" header "]

4. The role of the array function arsort is ____; the role of the error_reporting (2047) statement is ____.

A: arsort: sorts arrays in reverse order and maintains the index relationship error_reporting (2047). report All errors and warnings

5. write a regular expression to overwrite all JS/VBS scripts on the web page (that is, remove the script tag and its content ):

$ Script = "the following content is not displayed :";
Echo preg_replace ("/ ]. *?>. *? /Si "," Replace content ", $ script );
?>

6. install PHP using the Apache Module. in the http. conf file, first use the statement ____ to dynamically load the PHP module,
Then, use the statement ____ to make Apache process all the files with the extension of php as PHP scripts.
A: LoadModule php5_module "c:/php/php5apache2. dll"; AddType application/x-httpd-php. php

See reference manual directory II. installation and configuration 6. installation in Windows and Apache 2.0.x in Microsoft Windows

7. the include and require statements can both include another file to the current file. The difference between them is ____. to avoid multiple inclusion of the same file, you can replace them with ____ statements.
A: When the processing fails, include () generates a warning and require () leads to a fatal error. require_once ()/include_once ()

8. a function parameter cannot be a reference to a variable, unless the ____ is set to on.
A: allow_call_time_pass_reference boolean: indicates whether to enable mandatory parameter transfer when a function is called by reference. for details, see Appendix G of the reference manual.

9. the meaning of left join in SQL is __. if tbl_user records the student name and student ID ),
Tbl_score records the student's student ID (ID), score (score), and subject (subject ), to print the student name and the total score of each subject, use the SQL statement ____.

Answer: naturally left outer join

Create database phpinterview;
Use phpinterview
Create table tbl_user
(
ID int not null,
Name varchar (50) not null,
Primary key (ID)
);
Create table tbl_score
(
ID int not null,
Score dec (6, 2) not null,
Subject varchar (20) not null
);

Insert into tbl_user (ID, name) values (1, 'beimu ');
Insert into tbl_user (ID, name) values (2, 'aihui ');
Insert into tbl_score (ID, score, subject) values (1, 90, 'China ');
Insert into tbl_score (ID, score, subject) values (1, 80, 'mat ');
Insert into tbl_score (ID, score, subject) values (2, 86, 'mat ');
Insert into tbl_score (ID, score, subject) values (2, 96, 'China ');

Select A. id, sum (B. score) as sumscore
From tbl_user A left join tbl_score B
On A. ID = B. ID
Group by A. id

10. in PHP, heredoc is a special string whose end mark must be ____
A: The row where the end identifier is located cannot contain any other characters ";"

11. write a function to traverse all files and subfolders in a folder.

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 assumermui "));
?>

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.