Php interview questions and answers

Source: Internet
Author: User
Php interview questions and answers

  1. $ Img = file_get_contents ('http: // www.baidu.com/img/baidu_logo.gif ');
  2. File_put_contents('1.gif ', $ img );
  3. Echo '';
  4. ?>

3,

  1. Function is_gfriend ($ na, $ nb)

  2. {
  3. $ Random1 = rand (1/5); // calculate their fate
  4. $ Random2 = rand (1, 5 );
  5. If ($ random1 ==$ random2)
  6. Return $ na. "+". $ nb. "You have fate ";
  7. Else
  8. Return $ na. "+". $ nb. "Unfortunately, no fate ";

  9. }

  10. Echo is_gfriend (a, B );
  11. ?>

4,

Company interview questions: Baidu web development engineer pen questions]

Part 1: 1. explain the meaning of the following statement: document. form ["formname"]. submit;

2. the following statements are available:Write code. when you move the cursor over the text box, the content in the text box is automatically selected.

3. convert the character 09 to a decimal number.

4. convert 1234567890 to 1,234,567,890. every 3 digits are separated by commas.

5. I forgot about html and css.

6. enter a year in the text box to judge the Chinese zodiac and output it next to the text box. Both html and javaservlet are required.

7. ajax retrieves data from the server {id: 123, name: "baidu", username: "mm", checked: true}; analyzes the value of name ("baidu "). (The question is too long to remember)

8. about the customer experience. (Script school bbs.it-home.org editing)

Answer: 1. obtain the submit button element of the formname form.

2,

3,

  1. $ A = "09 ";
  2. Echo (int) $;
  3. Echo"
    ";
  4. Echo intval ("09 ");
  5. ?>

4,

  1. $ Num = preg_replace ('/(? <= [0-9]) (? = (? : [0-9] {3}) + (?! [0-9])/', $ num );
  2. Echo $ num;?>

6,

  1. $ T = 1986;
  2. Switch ($ t)
  3. {
  4. Case 1986:
  5. Echo "Niu ";
  6. Break;
  7. Case "":
  8. Break;
  9. Case "":
  10. Break;
  11. ......
  12. }

8. analyze satisfaction, endurance, and feedback.

Part 2:

1. the common idea of ajax, database triggers, gui, and interrupt mechanisms. Let's talk about this idea (mechanism ).

2.change the beginning of a single word in an English document to a large one, which is included in doc.txt. You can write your ideas in multiple programming languages (c \ c ++, java, php...) and try to optimize your program.

3. about the data structure of the tree.

4. database optimization: there is a table product (id, name, price, count); the query speed is always slow: select * from product where price = 100; when a non-clustered index is added to the price Field, the query speed is still slow. (1) analyze the cause of slow query. (2) how to optimize it.

5.

  1. Create table topid {
  2. Topicid int not null primary key auto_increment,
  3. Title text,
  4. Author varchar (30 ),
  5. Content blob,
  6. Isdeleted int
  7. ... // It seems that an index is defined on author.
  8. }
  9. Create table reply {
  10. Topicid int foreign key,
  11. Replyid int primary key auto_increment,
  12. Replyauthor varchar (30 ),
  13. Replytime datetime,
  14. Context blob
  15. ... // Defines an index and key
  16. }

One is the topic table and the other is the reply table.

1. what are the shortcomings of performance. 2. query the reply time does not exceed a specific period of time, the reply author name with the title of the topic starting with mike, in the following query: (Programmer's house bbs.it-home.org editor)

  1. Select * from topic where replyid in (select replyid from reply where
  2. Replyauthor like 'Mike % 'and (currenttime ()-replytime

In terms of performance, what are the shortcomings of the preceding query statements? How to optimize it?

Answer: 1. the database trigger and interrupt mechanism are automatically completed by the database, while the ajax trigger is triggered by the user. Ajax asynchronously optimizes the gui and database.

2,

  1. $ Fp = fopen ("aa.txt", 'r'); // English document aa.txt
  2. While (! Feof ($ fp )){
  3. $ Char = fgets ($ fp );
  4. }
  5. $ E = explode (",", $ char );
  6. $ Write = fopen ("doc.txt", 'w'); // create if no doc.txt exists
  7. Foreach ($ e as $ w)
  8. {
  9. If ($ w = $ e [count ($ e)-1]) // enter if ($ w = end ($ e) without a comma in the last word ))
  10. $ W = ucwords ($ w); // convert the first letter to uppercase
  11. Else
  12. $ W = ucwords ($ w ).",";
  13. Echo $ w;
  14. Fwrite ($ write, $ w); // write to doc.txt
  15. }
  16. Fclose ($ write );
  17. Fclose ($ fp );
  18. ?>

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.