PHP Pen Questions

Source: Internet
Author: User
Tags echo date php script script tag

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

Solution: Echo Date (' y-n-d h:i:s ', Strtotime ('-1 day '));

Reason:

Format character description return value example a lowercase morning and afternoon value AM or PMA uppercase morning and afternoon value am or the day ordinal of the PMD month, 2 digits with leading zeros 01 to 31D days of the day of the week, text representation, 3 letters Mon to SUNF month, full text format, such as Ja Nuary or Marchjanuary to Decemberg hours, 12-hour format, no leading 1 to 12G hours, 24-hour format, no leading 00 to 23h hours, 12-hour format, with leading 1 to 12H hours, 24-hour format, with leading 000 to 23i minutes with leading zeros 00 to 59>i if daylight saving time is 1, otherwise for the day of the 0j month, there is no leading 1 to 31l (lowercase letter of "L") days of the week, and the full text format Sunday to Saturdayl is a leap year if the leap year is 1, otherwise a 0m digit month, there is a leading 1 to 12M three letter abbreviation for the month of Jan to DECN number, there is no leading 1 to 12O and Greenwich Mean time difference of hours for example: +0200RRFC 822 Format Date Example: Thu, Dec 200 0 16:01:07 +0200s seconds, with a leading 0 to 59>s the English suffix after the number of days, 2 characters st,nd,rd or th. Can be used with J. T a given month should have a number of days 28 to 31T local time zone for example: EST,MDT ("translator note" in Windows for the full text format, for example, "Eastern Standard Time", the Chinese version will show "China"). The day of the W week, the number represents 0 (representing Sunday) to 6 (for Saturday) the week of the WISO-8601 format year, starting from Monday (PHP 4.1.0 New) For example: 42 (42nd Week of the Year) the year of the full representation of the Y4 digits for example: 1999 or 2003y2 Number of years represented by digits such as: Day 0 to 366 in the 99 or 03z years

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

Solution: In fact, PHP itself is a template engine, I used the smarty, common and phplib,fasttemplate,savant here is a list of templates engine

: Http://www.sitepoint.com/forums/showtHRead.php?t=123769

3. What tools are used for version control?

Solution: CVs and SVN,SVN, known as the next generation of CVS, are powerful, but CVS is a veteran and a high percentage of the market. I have been using SVN, the topic is to ask what tool, er, this may need to answer: CVS Server on Apache as the service side, Wincvs as a client; Subversion on Apache/dav do the server, TortoiseSVN do the client, or Subclipse do the client.

4, how to implement string rollover?

Solution: Use the Strrev function, do not use PHP built-in on their own write:

  

function Strrev ($STR)

{

$len =strlen ($STR);

$newstr = "";

for ($i = $len; $i >=0; $i –)

{

$newstr. = $str {$i};

}

return $newstr;

}

5. How to optimize MySQL database?

My answer:

(1). Database design Aspects, this is the responsibility of the DBA and architect, the design of a well-structured database, when necessary, to regularization (English is this: denormalize, Chinese translation into what I do not know), allow partial data redundancy, avoid join operation, to improve query efficiency

(2). System architecture design, the table hash, the huge amount of data scattered into several different tables. quick table, fast table only keep the latest data, slow table is a historical archive. Cluster, master server Read &

Write, from server read only, or n server, each machine is master

(3). (1) and (2) Beyond PHP programmer requirements, will be better, will not matter. Check for fewer indexes

(4). Write efficient SQL statements to see if there are any inefficient SQL statements, such as the full connection of the generated Cartesian product, a large number of group by and order by, no limit, and so on. When necessary, the database logic is encapsulated in the DBMS side of the stored procedure. Cache query Results, Explain of each SQL statement

(5). All that is required is to fetch only the necessary data from the database, such as querying the number of comments for an article, select COUNT (*) ... where article_id =? So, don't select * ... where article_id =? Then Msql_num_rows. Only the required SQL statements, such as when modifying the article, if the user only modified the title, then update ... set title =? where article_id =? Do not set content =? (large text)

(6). When necessary, use a different storage engine. For example, InnoDB can reduce deadlocks. Heap can increase query speed by an order of magnitude.

6, talk about transaction processing?

Solution: As is a programming language will have promised Hello World example, is the textbook of this database will say a to B's account transfer $50 example, to answer this. But as far as I know, with the MySQL company, MySQL is seldom used for transaction processing. And now Oracle has acquired InnoDB's company.

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

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

Solution: Mb_substr ()

9, Echo (), print (), Print_r () difference

Solution: ECHO is the language structure, no return value, print function and echo basically the same, the difference is that print is a function, there is a return value; Print_r is a recursive print for outputting array objects

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

Solution: Echo $_server[' php_self ']; echo $_server["Http_referer"];

11, the execution program segment will output??

Solution: 0

12, in HTTP 1.0, what is the meaning of status code 401, if you return the "File not found" prompt, the header function is available, the statement why.

Solution: Unauthorized Header ("http/1.0 404 Not Found");

13, the function of array function arsort is (reverse sorting and maintain the index relationship); the function of statement error_reporting (2047) is (all errors and warnings).

14. The database connection string format in Pear is ()?

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

16, the Apache module to install PHP, in the file http.conf the first to use the statement (1) to dynamically load the PHP module, and then use the statement (2) so that Apache will all the file extension php as PHP script processing.

Solution: (1) LoadModule php5_module "D:/xampp/apache/bin/php5apache2.dll" (2) 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, what is the difference between them, in order to avoid containing the same file multiple times, you can replace them with a statement ().

Solution: An exception occurs when 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, the function to be used is (serialize ()/unserialize ())

19. A function parameter cannot be a reference to a variable unless the (allow_call_time_pass_reference) is set to on in PHP.ini.

20, the meaning of the left join in SQL is (natural outer connection).

If Tbl_user records the student's name and school 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 corresponding section scores, you can use the SQL statement: select name, Count (score) as Sum_score from Tbl_user left join Tbl_score on tbl_user.id=t Bl_score.id GROUP BY Tbl_user.id

21. In PHP, Heredoc is a special string whose end flag must be (the line where the end identifier is located cannot contain any other characters except ";").

22. Write a function that can traverse all the files and subfolders under a folder.

Solution

  

/** * 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] = Rec_scandir ($dir. "/" . $file);

}else {

$files [] = $file;

}

}

}

Closedir ($handle);

return $files;

}

}

23. Brief introduction of the principle of infinite classification in the forum.

24, design a Web page, so that when it opens a full-screen window, the window has a text box and a button. The user clicks the button to close the window while entering the information in the text box, and the input information is displayed on the main page.

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.