Home Backend Development PHP Tutorial Online communication is an interview question for PHP programmers at Tencent

Online communication is an interview question for PHP programmers at Tencent

Jul 25, 2016 am 08:59 AM

  1. while (list($k,$v) = each($data)) {

  2. $encoded .= ($encoded ? "$sep" : "");
  3. $encoded .= rawurlencode($k)."=".rawurlencode($v);
  4. }
  5. Return $encoded;
  6. }

  7. Function post($url, $post, $cookie){

  8. $url = parse_url($url);
  9. $post = encode($data, ‘&’);
  10. $cookie = encode($cookieArray, ‘;’);
  11. $fp = fsockopen($url['host'], $url['port'] ? $url['port'] : 80, $errno, $errstr, 10);
  12. if (!$fp) return "Failed to open socket to $url[host]";

  13. fputs($fp, sprintf("POST %s%s%s HTTP/1.0n", $url['path'], $url['query'] ? "?" : "", $url['query']));

  14. fputs($fp, "Host: $url[host]n");
  15. fputs($fp, "Content-type: application/x-www-form-urlencodedn");
  16. fputs($fp, "Content-length: " . strlen($encoded) . "n");
  17. fputs($fp, "Cookie: $cookienn");
  18. fputs($fp, "Connection: closenn");
  19. fputs($fp, "$post n");

  20. while (!feof($fp)) {

  21. echo fgets($fp, 128);
  22. }
  23. fclose($fp);
  24. }

  25. $url = ‘http://bbs.it-home.org:8080/test’;

  26. $encoded = username=温柔一刀& pwd=
  27. $post = array(
  28. ‘username’=> ‘温柔一刀’,
  29. ‘pwd => ‘&123=321&321=123&’,
  30. ‘intro => ‘Hello world!’
  31. );
  32. $cookie = array(
  33. ‘cur_query’ => ‘you&me,
  34. ‘last_tm’ => time() - 600,
  35. ‘cur_tm ‘=> time()
  36. );

  37. Post($url, $post, $cookie);

复制代码

11.你用什么方法检查PHP脚本的执行效率(通常是脚本执行时间)和数据库SQL的效率(通常是数据库Query时间),并定位和分析脚本执行和数据库查询的瓶颈所在? 1.脚本执行时间,启用xdebug,使用WinCacheGrind分析。 2.数据库查询,mysql使用EXPLAIN分析查询,启用slow query log记录慢查询。

PHP LAMP Engineer Test Paper Question 1 What does echo count ("123") ?> print out? A) 3 B) False C) Null D) 1 E) 0

Question 2 Which of the following snippets prints a representation of 42 with two decimal places? A) printf("%.2dn", 42); B) printf("%1.2fn", 42); C) printf("%1.2un", 42);

Question 3 Given $text = 'Content-Type: text/xml'; Which of the following prints 'text/xml'? A) print substr($text, strchr($text, ':')); B) print substr($text, strchr($text, ':') + 1); C) print substr($text, strpos($text, ':') + 1); D) print substr($text, strpos($text, ':') + 2); E) print substr($text, 0, strchr($text, ':')

Question 4 What is the value of $a?

  1. $a = in_array('01', array('1')) == var_dump('01' == 1);
  2. ?>
复制代码

A) True B) False

Question 5 What is the value of $result in the following PHP code?

  1. function timesTwo($int) {
  2. $int = $int * 2;
  3. }
  4. $int = 2;
  5. $result = timesTwo($int);
  6. ?>;
复制代码

Answer: NULL

Question 6 The code below ___________ because ____________.

  1. class Foo {
  2. ?>
  3. function bar() {
  4. print "bar";
  5. }
  6. }
  7. ?>
复制代码

A) will work, class definitions can be split up into multiple PHP blocks. B) will not work, class definitions must be in a single PHP block. C) will not work, class definitions must be in a single file but can be in multiple PHP blocks. D) will work, class definitions can be split up into multiple files and multiple PHP blocks.

Question 7 When turned on, ____________ will _________ your script with different variables from HTML forms and cookies. A) show_errors, enable B) show_errors, show C) register_globals, enhance D) register_globals, inject

Question 8 What will be the output of the following PHP code:

  1. echo count(strlen("http://php.net"));
  2. ?>
复制代码

Answer: 1

Question 9 What is the best all-purpose way of comparing two strings? A) Using the strpos function B) Using the == operator C) Using strcasecmp() D) Using strcmp()

Question 10 What is the difference between "print()" and "echo()"? Answer: print is a function,echo is a language construct



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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

See all articles