PHP face test Sharing (Blessed are the friends who are looking for a job)

Source: Internet
Author: User
Tags call back
    1. $tmp = 0 = = "a"? 1:2;
    2. Echo $tmp;
    3. ?>
Copy Code

Result of 1 int and string cast, 0=== "a"

0 = = 0 must be true. PHP is a weak type. $tmp = 0 = = = = "a"? 1:2;echo $tmp; This is 2.

4. A string is known as follows: $str = "1109063 Milo 1"; 1109063 is assigned to $uid in a line of code, Milo is assigned to $user, and 1 is assigned to $type space as list ($uid, $user, $type) = E Xplode ("", $str); \ t below list ($uid, $user, $type) = explode ("\ t", $str), List ($uid, $user, $type) = sscanf ($str, "%d%s%d"); $ n = sscanf ($auth, "%d\t%s%s", $id, $first, $last);

5. The following types of signed and unsigned ranges are listed TINYINT SMALLINT mediumint inttinyint-2^7-2^7-10 ~ 2^8-1smallint-2^15-2^15-1 0 ~ 2^16-1mediumint -2^23-2^23-1 0 ~ 2^24-1int-2^31-2^31-1 0 ~ 2^32-1

6. Assemble the following array in one line into a string I am milo! Day up!

    1. $arr = Array (
    2. ' I ', ' AM ', ' milo! ', ' Day ', ' Day ', ' up! '
    3. );
    4. ?>
    5. $str = Strtolower (Implode ("", $arr));
Copy Code

7. Call the following function to get the function and get the value of Count

    1. function get_list ($cnd = Array (), & $count = False)
    2. {
    3. Pseudo-code handles $CND and assigns values Datas
    4. $datas = ' I am call back ';
    5. $count && $count = rand (1, 10000);
    6. return $datas;
    7. }
    8. ?>
    9. $count = 1;
    10. $data = get_list ($cnd,& $count);
    11. Echo $count;
Copy Code

8. Several ways to replace the session mechanism, simple description of their merits MySQL, memcache, cookies maintain a unique status identification code

9. Possible causes of the following HTTP status codes, how to handle 200, 301, 404, 502, 503200 requests have been successful, the requested response header or data body will be returned with this response. 301 the requested resource has been permanently moved to a new location, and any future references to this resource should use one of several URIs returned by this response. If possible, clients that have link editing capabilities should automatically modify the requested address to the address returned from the server.   Unless otherwise specified, the response is cacheable. The new permanent URI should be returned in the location domain of the response.   Unless this is a HEAD request, the response entity should contain a hyperlink to the new URI and a short description. If this is not a GET or HEAD request, the browser disables automatic redirection unless the user confirms it, because the requested condition may vary.

Note: For some browsers that use the http/1.0 protocol, when they send a POST request that gets a 301 response, the next redirect request becomes a Get method.

404 the request failed and the requested resource was not found on the server. No information can tell the user whether the situation is temporary or permanent. If the server knows the situation, it should use the 410 status code to tell the old resources because of some internal configuration mechanism problems, has been permanently unavailable, and there is no jump to the address. 404 This status code is widely used when the server does not want to reveal exactly why the request was rejected or if no other appropriate response is available. 502 An invalid response was received from the upstream server when a request was attempted by a server that is a gateway or agent working. 503 The server is currently unable to process requests due to temporary server maintenance or overloading. This situation is temporary and will be resumed after a certain period of time. If the delay time can be estimated, then the response can include a retry-after header to indicate the delay time.   If this retry-after message is not given, the client should handle it in a manner that handles 500 responses. Note: The presence of a 503 status code does not mean that the server must use it when it is overloaded. Some servers simply want to deny connections to clients.

All OK, the answer document for Get and post requests is followed. 301 Moved Permanently The document requested by the customer elsewhere, the new URL is given in the location header, and the browser should automatically access the new URL404 not Found unable to find the resource at the specified position. This is also a common answer. 502 Bad Gateway server as a gateway or proxy, the server returned an illegal reply in order to complete the request to access the next server. 503 Service Unavailable Server failed to answer due to maintenance or heavy load. For example, a servlet might return 503 if the database connection pool is full. A retry-after header can be supplied when the server returns 503.

10. Have the following database, use the original ecological MySQL extension to connect and query the first 10 rows of the user table Host:192.168.0.254port:3306user:onepass:piecedatabase:db_usertable:user

    1. $link = mysql_connect ("192.168.0.254:3306", "one", "piece") or Die (' Could not connect: '. Mysql_error ());
    2. mysql_select_db (' Db_user ', $link);
    3. $query = mysql_query ("SELECT * from User limit 10");
    4. while ($rs = Mysql_fetch_array ($query, MYSQL_ASSOC))
    5. {}
Copy Code

11. Use AutoLoad ($class) to implement automatic loading of classes in the Lib directory and to be compatible with subdirectories

  1. $request->action = Lcfirst (Implode (Array_map (

  2. ' Ucfirst ',
  3. Explode ('-', Strtolower ($request->action))
  4. )));
  5. ------------------------------------------------
  6. function __autoload ($class)
  7. {
  8. $cls = Strtolower (Str_replace ("_", "/", $class));

  9. if (File_exsits (LIB. $cls. php '))
  10. {
  11. Include_once (LIB $cls. php ');
  12. }
  13. Else
  14. {
  15. Die (' not found {$class} class ');
  16. }
  17. }
  18. Defined ("LIB", '/data/wwwroot/www.xx.com/lib/');
  19. $author = new Lib_author ();
  20. -----------------------------------------------------------
  21. function __authload ($class)
  22. {
  23. $cls = Explode ("_", $class);
  24. if (@is_dir ($cls [1])
  25. {
  26. if (@is_file ($cls [2])
  27. {
  28. Include_once ("Con_path". $cls [1]. ' /'. $cls [2]. ". PHP ");
  29. }
  30. Else
  31. {
  32. Dir (' Error ');
  33. }
  34. }
  35. else if (@is_file ($cls [1]. ". PHP "))
  36. {
  37. Include_once ("Con_path". $cls [1]. ". PHP ");
  38. }
  39. Else
  40. {
  41. Dir (' Error ');
  42. }
  43. }
  44. ---------------------------------------
  45. function __autoload ($class)
  46. {
  47. $cls = Explode ("_", $class);
  48. $file = Get_file ($CLS);
  49. if ($file = = ' ERROR ')
  50. {
  51. Die (' Error ');
  52. }
  53. Include_once ($file);
  54. }
  55. function Get_file ($dir)
  56. {
  57. if (Is_array ($dir))
  58. {
  59. foreach ($dir as $k = $v)
  60. {
  61. $tmpdir. = $v. '/';
  62. if (Is_dir (' Con_path '. $tmpdir))
  63. {
  64. Continue ();
  65. }
  66. else if (is_file (' Con_path '. $tmpdir. "). PHP "))
  67. {
  68. Return ' Con_path '. $tmpdir. ". PHP ";
  69. }
  70. Else
  71. {
  72. Return ' ERROR ';
  73. }
  74. }
  75. Return ' ERROR ';
  76. }
  77. Return ' ERROR ';
  78. }

  79. Defined ("Con_path", "/data/wwwroot/www.xx.com/app/cntroller/");

  80. $SB = new CONTROLLER_SB ();
  81. ------------------------------------
  82. function __autoload_my_classes ($classname)
  83. {
  84. # ... your logic to include classes here
  85. }
  86. Spl_autoload_register (' __autoload_my_classes ');
  87. -----------------------------------------------------------

Copy Code

12. Use Set_error_handle to catch errors and output, level yourself

    1. Set_error_handle (callback,level)

    2. function callback (int $errno, string $e Rrstr [, String $errfile [, int $errline [, array $errcontext]]) {
    3. }

    4. Function Dealerrorhan Dler ($errno, $errstr, $errfile, $errline)

    5. {
    6. switch ($errno) {
    7. case e_user_error:
    8. echo "error [$errno] $errstr fatal error on line $errline in file $errfile";
    9. break;
    10. Case e_user_warning:
    11. echo My warning [$errno] $errstr ":
    12. break;
    13. Case E_user_notice:
    14. echo "My notice[$errno] $errstr";
    15. break;
    16. Default:
    17. echo "UNKONWN error type: [$errno] $errstr";
    18. break;
    19. }
    20. }
    21. Set_erro_handler (dealerrorhandler);

    22. Trigger_error ("notice", e_user_notice);

    23. trigger_error ("Warning", e_user_warning);
    24. trigger_error ("error", E_user_error);

Copy Code

13. Briefly describe two methods of notice warning to block PHP programs initialize variables, file start setting error level or modify php.ini settings Error_reportingset_error_handler and @ suppress errors

1. Add: Error_reporting (E_all & ~e_notice); 2. or modify in php.ini: Error_reporting = E_all instead: error_reporting = E_all & ~e_notice3.error_reporting (0); or modify Php.inidisplay_errors=off 1 2 3 4 Next last

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