Home > Backend Development > PHP Tutorial > PHP interview questions and answers sharing

PHP interview questions and answers sharing

WBOY
Release: 2016-07-25 08:53:45
Original
1047 people have browsed it
  1. $img = file_get_contents('http://www.baidu.com/img/baidu_logo.gif');
  2. file_put_contents('1.gif',$img);
  3. echo ' ';
  4. ?>
Copy code

3.

  1. function is_gfriend($na,$nb)

  2. {
  3. $random1=rand(1,5);//Calculate that they have 1/5 fate
  4. $ random2=rand(1,5);
  5. if ($random1==$random2)
  6. return $na."+".$nb."You are destined";
  7. else
  8. return $na."+".$nb ."It's a pity that there is no fate";

  9. }

  10. echo is_gfriend(a,b);
  11. ?>

Copy code

4,

Company interview questions: Baidu web development engineer written test questions】

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

2. There are the following statements: Write code so that when the mouse moves over the text box, the content in the text box is automatically selected.

3. Convert character 09 into decimal number.

4. Convert 1234567890 into 1,234,567,890 by separating every 3 digits with commas.

5. I forgot about html and css.

6. Enter a year in the text box, determine its zodiac sign, and output it next to the text box. Both html and javaservlet are required to be written.

7.ajax retrieves data from the server {id:123, name:"baidu", username:"mm",checked:true}; Analyze the value corresponding to name ("baidu"). (The question is long, I can’t remember)

8. Talk about customer experience. (Edited and compiled by Scripting School bbs.it-home.org)

Answer: 1. Get the formname form submit button element.

2,

Copy code

3、

  1. $a="09";
  2. echo ( int ) $a;
  3. echo "
    ";
  4. echo intval("09" ; ])(?=(?:[0-9]{3})+(?![0-9]))/', ',', $num);
  5. echo $num; ?>
Copy code

6,

  1. $t= 1986;
  2. switch ($t)
  3. {
case 1986:
echo "cow";break;case "":
break;

case " ":

break;
...
}
  1. Copy code
  2. 8. Analysis from satisfaction, tolerance, and feedback.
  3. Part 2:
  4. 1. Common ideas of ajax, database trigger, gui, and interrupt mechanism. Let’s talk about this idea (mechanism).
  5. 2. Convert the first letters of all words in an English document to uppercase, and the document is stored in doc.txt. You can choose from a variety of programming languages ​​​​(cc++, java, php...) to write out your ideas and try to optimize your program.
  6. 3. About the data structure of tree.
4. Database optimization: There is a table product(id,name,price,count); When executing the following query, the speed is always very slow: select * from product where price=100; Adding a non-clustered index to the price field, the query speed is still very slow. (1) Analyze the reasons for slow query. (2) How to optimize. 5.

create table topid{

topicid int not null primary key auto_increment,

title text,

author varchar(30),

content blob,

isdeleted int

...... //It seems An index is defined on author

}

create table reply{

topicid int foreign key,
replyid int primary key auto_increment,
replyauthor varchar(30),
    replytime datetime,
  1. context blob
  2. ..../ / Define an index and key
  3. }
  4. Copy the code
  5. One is the topic table and the other is the reply table.
  6. 1. Ask what are the shortcomings of doing this in terms of performance. 2. Query the topics whose reply time does not exceed a specific time period and the author's name of the reply starts with mike title, query as follows: (Edited and compiled by Programmer’s Home bbs.it-home.org)
  7. select * from topic where replyid in (select replyid from reply where
replyauthor like 'mike%' and (currenttime()-replytime
Copy code

What are the shortcomings of the above query statement in terms of performance? How to optimize?

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

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');//If there is no doc.txt, create
  7. foreach ($ e as $w)
  8. {
  9. if($w==$e[count($e)-1])//The last word is entered without a comma if($w==end($e))
  10. $w= ucwords($w);//Convert the first letter to uppercase
  11. else
  12. $w=ucwords($w).",";
  13. echo $w;
  14. fwrite($write,$w);//Write doc .txt document
  15. }
  16. fclose($write);
  17. fclose($fp);
  18. ?>
Copy code


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template