Inbox? Php??

Source: Internet
Author: User
1. The time format of the day before printing with PHP is 2006-5-10 22:21:21

Date_default_timezone_set (' PRC '); Set China time zone

echo $today =date ("Y-m-d h:i:s", (Time ()-86400)); Yesterday??

2, Echo (), print (), Print_r () difference

ECHO is a PHP statement, print and Print_r are functions, the statement does not return a value, the function can have a return value (even if it is not used)
Print only prints out values for simple type variables (such as int,string)
Print_r can print out values for complex type variables (such as arrays, objects)

3. In PHP and C, there are two types of increment and post increment, essentially, both pre-increment and post-increment increase the value of the variable, and the effect on the variable is the same. The difference is the value of the increment expression. Before incrementing, write "+ + $variable", to increase the value (PHP before reading the value of the variable, increase the value of the variable, so called "pre-increment"). After increment, write "$variable + +", the original value of the variable is not incremented (PHP after reading the value of the variable, increase the value of the variable, so called "after Increment").

$a = 1;

$b = $a + +;

The value of the $b? 1

3. Which tools are used for version control?

SNV (Subversion), VSS (source code manager), etc.

4. How do I implement string flipping?

$luokuan = "abcdefg-Test ah-!!! One two three four five.. ";

$n = Mb_strlen ("$luokuan");

Echo $n;

$newluokuan = "";

for ($i = $n; $i >=0; $i--)

{

$newluokuan. = substr ($luokuan, $i, 1);

$newluokuan. = Mb_substr ($luokuan, $i, 1, ' utf-8 ');

}

Echo $newluokuan;

Do not consider mixing in Chinese and English, not the optimal algorithm, without the PHP library function to flip the string:

5. How to optimize MySQL database

1. Select the most applicable field properties

2. Use connection (join) instead of subquery (sub-queries)

3. Use Union (Union) instead of manually created temporary table

4. Business

5. Lock the table

6. Using foreign keys

7. Use Index

6, the ability to make HTML and PHP separated from the use of the template

Smarty,phplib,smarttemplate ...

7. Talk about transaction processing

Can control the concurrent transaction generated data synchronous commit, update problem, is a lock concept. Comit,rollback

8, apache+mysql+php to achieve maximum load method

Ask too general, generate static HTML page, squid reverse proxy, apache,mysql load balancer.

9, the implementation of the text string interception without garbled method.

The first thing to consider is the character set, UTF-8 the next Chinese character accounted for 3 bytes, gbk the next Chinese character accounted for 2 bytes. You can write a function to deal with, others have written a lot, of course, you can also open the Mbstring extension library, using the inside of the MB_SUBSTR () and other functions to intercept

10.

var $empty = ';

var $null = null;

var $bool = FALSE;

var $notSet;

var $array = array ();

$a = "Hello";

$b = & $a;

Unset ($b);

$b = "World";

What is $a?

Hello,unset ($b) just released $b himself and $ A in the alias relationship, and will not release $ A

$a = 1;

$x = & $a;

$b = $a + +;

What is $b?

1, first execute $b = $a, $a + + again, so $b or 1

$x = Empty ($array);

What is $x? True or False

True, $array is an empty array

12. Have you ever used version control software? If you have the name of the version control software you are using?

Cvs:wincvs, is a client of CVS

VSS, Microsoft products, more suitable for small and medium-sized projects, only support single checkout

13. Have you ever used a template engine? If you have the name of the template engine you are using?

Smarty,php officially recommended template engine, it is a compiled template, not the same as phplib, powerful, more than 30 kinds of tags, support the cache

14. What are the methods you use to solve traffic problems for large-volume websites?

squid[Reverse proxy], the best choice! Of course, money is not a problem, increase the bandwidth is also a good choice!

15. Write the code that displays the client IP and server IP in PHP:

echo $_server[' REMOTE_ADDR '//Client IP

echo $_server[' server_addr '//server-side IP

Interview Question 3

First, Php/mysql programming

1) in a content management system, the table message has the following fields
ID Article ID
Title of title article
Content article contents
CATEGORY_ID article Category ID
Hits Click Volume

Create the table above and write out the MySQL statement

CREATE TABLE Message

(

ID INT not NULL auto_increment PRIMARY KEY,

Title varchar (100),

Content varchar (225),

category_id int,

Hits int

)

MSSQL sentence:

CREATE TABLE Message

(

ID INT Identity (+) is not null primary key,

Title varchar (100),

[Content] varchar (225),

[category_id] int,

Hits int

)

2) Same as above Content Management system: Table comment Record user reply content, fields as follows

comment_id Reply ID

ID article ID, ID in the associated message table

Comment_content Reply Content

Now by querying the database need to get the following format of the article title list, and according to the number of replies sorted, reply to the highest ranked in the front

Article ID article title click Reply Quantity

Use an SQL statement to complete the above query, if the article does not reply to the number of replies displayed as 0

Select a.ID, A.title, A.hits, if (Ifnull (B.id,false), COUNT (*), 0) as replay from message a left join comment B on a.id=b.id

GROUP BY a.ID

ORDER BY replay DESC

3) The above Content management system, table category to save the classification information, the fields are as follows (3 points)

category_id Int (4) not NULL auto_increment;

Categroy_name varchar (+) not null;

When a user enters an article, select the article category by selecting the drop-down menu

Write how to implement this drop-down menu

function CategoryList ()

{

$result =mysql_query ("Select Category_id,categroy_name from category")

Or Die ("Invalid query:".) Mysql_error ());

Print (""N"); while ($rowArray =mysql_fetch_array ($result)) {print ("". $rowArray [' Categroy_name ']." " n "); } print ("");

}

Third, PHP program

1) write out the output of the following program

$b = 201;

$c = 40;

$a = $b > $c? 4:5;

echo $a;

?>

$a =4

2) write out the output of the following program

$STR = "CD";

$ $str = "Hotdog";

$ $str. = "OK";

Echo $str;

?>

$STR = "CD";

Four

1. Please indicate the difference between the value of the transfer and the reference in PHP. When is the value passed?

Passing a value simply passes the value of a variable to another variable, and the reference indicates that the two points to the same place.

2 What is the function of error_reporting in PHP?

Sets the error reporting level for PHP scripts.

3 Use regular Expressions (Regular expression) to write a function to verify that the e-mail message is in the correct format.
/*
Check if the e-mail address is a mail address and return a logical value
*/
function Checkmailadr ($STR) {
Return (eregi ("^[_\.0-9a-z-]+@" ([0-9a-z][0-9a-z-]+\.) +[a-z]{2,3}$ ", $str));
}

4 briefly describes how to get the current execution script path, including the obtained parameters.
Description: For example, there is a script www.domain.com, the parameters passed to him are parameter 1, parameter 2, Parameter 3 .... The way to pass parameters is probably that get is a post, so now write something like: http://www.domain.com/script.php? parameter 1= value 1& parameter 2= value 2 ... The results
About the pre-execute script path feels a bit ambiguous: if you get the script on the server absolute path with $_server[' Appl_physical_path ']. If the URL of the script can be used to get
Get all parameters: You can use the following methods:
Get the data for the post
while (list ($var, $value) = each ($HTTP _post_vars))
{
echo "$var = $value n";
}
Get data for Get mode
while (list ($var, $value) = each ($HTTP _get_vars))
{
echo "$var = $value n";
}

5 There is a one-dimensional array that stores the shaping data, write a function that arranges them in order from large to small. Requires high efficiency of execution. and explain how to improve the efficiency of execution.
(The function must be implemented by itself and cannot use PHP functions)
Can be sorted by bubbling

function Bubblesort ($STR)
{
for ($i =0; $i
{
For ($j =count ($STR)-2; $j >= $i; $j-)
{
if ($str [$j +1]< $str [$j])
{
$tmp = $str [$j +1];

$str [$j +1]= $str [$j];
$str [$j]= $tmp;
}

}

}
return $str;
}
$str = Array (3,6,1,5,9,0,4,6,11);
Print_r (Bubblesort ($STR));
?>

6 Please give an example of how you can speed up page loading in your development process
A Generate static HTML,

B Generate XML
C Accelerate with Zend

Interview Question 8
1-How to tell if a window has been masked by JavaScript.


2-Write the session's operating mechanism

User A accesses Site y, if site y executes session_start (), (the following assumes that Session_Start () always exists) then a session_id is generated, the session The ID is generally saved to user A in the form of a cookie (we can force the SESSION ID to be passed in a cookie by setting the Session.use_only_cookies to 1 in php.ini. )。 The session ID is displayed as $_cookie[' Phpsessid ']; (Phpsessid can be modified with the Session_name () function)

User A then accesses, and the session ID ($_cookie[' phpsessid ') is routed to site Y each time a accesses Y.

On site Y, there is a directory that is used to hold the actual data of the session. Site Y receives the session ID, and then passes the session ID to get an association with the session data and returns the session data.



3-Prevent SQL injection vulnerability generally with the _____ function.

Addslashes



Write the top 10-digit SQL, using the following table:
Members (Id,username,posts,pass,email)
SELECT Username,count (*) as num from "members" group by username order by COUNT (*) DESC LIMIT 10

5

Give you three number, write the program to find its maximum value.
$var 1=1;
$var 2=7;
$var 3=8;
$max = $var 1> $var 2? $var 1: $var 2;
$max = $max > $var 3? $max: $var 3;
Echo $max;

6) There is a Table menu (Mainmenu,submenu,url), please use the recursive method to write a tree menu, all the menu list to

JS Print

7. Execution of program segments

Will output 2

8. In HTTP 1.0, the meaning of status code 401 is

401 (unauthorized/not authorized)

401 (sc_unauthorized) indicates that the client accesses a password-protected page when there is no valid identity information in the authorization header information. This response must contain a www-authenticate of the authorization information header

9. The function of array function arsort is (); the function of statement error_reporting (2047) is ().

Arsort-Reverse sorting an array and keep the index relationship

Error_reporting (2047) all the?? Warning

All errors and warnings, as supported, except of level e_strict.

10. Please write out the PHP5 permission control modifier (3 points)

Private protected public

11. Please write the PhP5 constructor and destructor (2 points)

__construct __destruct

12. What is the function that gets the total number of query result sets? (1 points)

Mysql_num_rows ($res);

13. In PHP, the name of the current script (not including the path and query string) is recorded in the predefined variable (1), while the URL linked to the current page is recorded in the predefined variable (2).

echo $_server[' php_self ']; echo $_server["Http_referer"];

14. In HTTP 1.0, the meaning of status code 401 is (4); If you return a prompt for "file not found", the header function is available with the statement (5).

(4) Unauthorized (5) header ("http/1.0 404 Not Found");

15 write a regular expression that js/vbs all the scripts on the Web page (that is, remove the script tag and its contents): (9).

Echo preg_replace ("/dffffff");

16.: Install PHP in the Apache module, in the file http.conf first use the statement (10) to dynamically load the PHP module, and then use the statement (11) so that Apache will all the files with PHP extension as php script processing.

(10) LoadModule php5_module "D:/xampp/apache/bin/php5apache2.dll"

(one) AddType application/x-httpd-php-source. Phps

AddType application/x-httpd-php. php. php5. PhP4. php3. phtml

17. Statements include and require can include another file in the current file, the difference is (12), in order to avoid multiple inclusion of the same file, you can use the statement (13) instead of them.

(12) When an exception occurs, the include generates a warning require a fatal error (require_once ()/include_once ()

18. The properties of the class can be serialized and saved to the session so that the entire class can be restored later, and the function to be used is (14).

Serialize ()/unserialize ()

19. The argument of a function cannot be a reference to a variable unless (15) is set to on in PHP.ini.

Allow_call_time_pass_reference

The meaning of the left join in 20.SQL is (16).

(16) Natural left outer connection

21. If Tbl_user records the student's name (name) and number (ID),

Tbl_score recorded student (ID) and test scores (score) and test subjects (subject), which were expelled from the school after the exam,

To print out each student's name and the corresponding total, the SQL statement (17) can be used.

Select Name, count (score) as Sum_score from Tbl_user left join Tbl_score on Tbl_user.id=tbl_score.id GROUP by Tbl_us Er.id

22. In PHP, Heredoc is a special string, and its end flag must be (18).

The line where the end identifier is located cannot contain any other characters except ";"

23. A function that can traverse all the files and subfolders under a folder.

/**

* Traversing the directory, the result is stored in an array. Support PHP4 and above. PHP5 can replace the while loop with the Scandir () function later.

* @param string $dir

* @return Array

*/

function My_scandir ($dir)

{

$files = Array ();

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 [] = $file;

}

}

}

Closedir ($handle);

return $files;

}

}

  • 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.