PHP Classic face test collection _php skills

Source: Internet
Author: User
Tags explode image processing library sprintf svn

This paper analyzes the PHP classic questions in detail. Share to everyone for your reference. Specifically as follows:

Do a bit of the network on the PHP topic, unknowingly do now ... Post the answers for your reference.

1, use PHP to print out the day before the format is 2006-5-10 22:21:21 (2 points)

$a = Date ("y-m-d h:i:s", Strtotime ("-1 day"));
Print_r ($a);

2, Echo (), print (), Print_r () difference (3 points)
Echo and print are not a function, they are a language structure
int print (string $arg) with only one argument
Echo arg1,arg2; Can output multiple parameters, return void
Echo and print can only print a string and cannot print out the structure
Print_r can print out the structure
Like what

$arr = Array ("Key" => "value");
Print_r ($arr);

3, can make HTML and PHP separated from the use of the template (1 points)
Smarty,phplib

4. What tools are used for version control? (1 points)
Svn,git,cvs

5, how to implement string flip? (3 points)
English:
Strrev ($a)
Chinese or other text:
Chinese: GB2312, code is using GB2312 encoding

<?php 
function Reverse ($str)
{
 $ret = ""; 
 Len=mbstrwidth (str, "GB2312");
 for (i=0;i< len;i++)
 {
 arr[]=mbsubstr (str, $i, 1, "GB2312");
 }
 Return implode ("", Array_reverse ($arr));
Print_r (Reverse ("Hello"));

6, optimize the MySQL database method. (4 points, more writing)
Statement aspect:
1 using indexes to increase query efficiency
2 Optimizing the query statement to improve the index hit rate
The database covers aspects:
1 construct the Sub-Library to improve the storage and expansion of database
2 use different storage engines as needed

7, the Meaning of PHP (send 1 points)
Super Text preprocessing language
Hypertext Preprocessor

8, MySQL to obtain the current time function is?, the format of the date of the function is (2 points)

Current_timestamp ()
date_format ()
Select Date_format ("2011-11-21 10:10:10", "%y-%m-%d");

9, the implementation of the text string interception without garbled method. (3 points)

Mb_substr ($STR, 1, 1, "GB2312");

10, have you ever used version control software? What is the name of the version control software you are using? (1 points)
Svn
Git

11, have you used the template engine? What if you have the name of the template engine you're using? (1 points)
Smarty

12, please briefly describe your most proud development (4 points)
Xxx

13, for the large flow of the Web site, what method do you use to solve the problem of access volume? (4 points)
1 Efficient use of caching to increase cache hit rate
2 Using Load Balancing
3 using CDN for static files for storage and acceleration
4 ideas to reduce the use of the database
5 to see where the bottleneck of statistics occurs

14, in PHP to display the client IP and server IP code 1 points)
$_server["REMOTE_ADDR"]
$_server["SERVER_ADDR"]

15. What is the difference between statement include and require? To avoid including the same file multiple times, use (?) Statements instead of them? (2 points)
At the time of failure:
Include generates a warning, while require produces a direct error interrupt
Require load before running
Include loading at run time
Require_once
Include_once

16, how to modify the lifetime of the session (1 points).
Session_set_cookie_params

17, there is a web address, such as the PHP Lab homepage: http://www.jb51.net/index.html, how to get its content? (divided)
File_get_contents
Curl

18, in HTTP 1.0, the meaning of status code 401 is (?); If you return the prompt "file not found", the header function is available, and the statement is (?);( 2 points)
Not authorized

Header ("http/1.0 404 Not Found");

Fast CGI:

Header ("status:404 not Found");

19, in PHP, Heredoc is a special string, it's the end of the flag must be? (1 points)
into pairs appeared

$a = <<eod
good test
EOD;

20, talk about the advantages and disadvantages of asp,php,jsp (1 points)
ASP is required to rely on IIS, is the language developed by Microsoft
PHP and JSP can rely on other servers such as Apache or Nginx

21. Talk about the knowledge of MVC (1 points)
Model: Data structure layer
View: Show
Control: Receiving and judging processing input

22, write off the top number of the 10-person name of the SQL, using the following table: Members (Id,username,posts,pass,email) (2 points)
Select top Id,username from posts desc

23. Please explain the difference between the value in PHP and the reference in the pass. When does the value pass the reference? (2 points)
& Indicates a pass reference
parameter-passing reference in a function changes the parameters
It is generally possible to consider using references when there are multiple output parameters

24. What is the function of error_reporting in PHP? (1 points)
Set the display level of the error

25. Please write a function to verify that the e-mail message is in the correct format (2 points)

$str = "jianfeng@126.com";
Regex= "([a−z0−9\.−]+) @ ([\da−z\.−]+) \. ([A−z\.] 2,6) "; Regular return
Preg_match (REGEX,STR)

26. Briefly describes how to get the current execution script path, including the obtained parameters. (2 points)
$ARGC--Get the number of parameters
$ARGV--Get the argument list

27. How to modify the life time of the session. (1 points)
Session_set_cookie_params

28, JS form pop-up dialog box function is? Get the input focus function? (2 points)

Alert ()
Confirm ()
Promopt ()
Focus ()

29, JS steering function is? How to introduce an external JS file? (2 points)

window.location.href= "#"
<script src= "#" ></script>

30. What is the difference between foo () and @foo ()? (1 points)
@ represents all warning ignored

31. How do I declare a class that has no methods and attributes named "MyClass"? (1 points)

class MyClass
{
}

32. How to instantiate an object named "MyClass"? (1 points)

$myclass = new MyClass ();

33. How do you access and set the properties of a class? (2 points)

<?php
Class A
{public
 $name = "a";
}
$a = new A ();
n=a->name;
Print_r ($n);

34. What is the difference between mysql_fetch_row () and mysql_fetch_array? (1 points)
Mysql_fetch_array () is an extended version of Mysql_fetch_row (). In addition to storing data in an array as a digital index, you can store the data as an associated index, using the field name as the key name.

<?php
mysql_connect ("localhost", "Mysql_user", "Mysql_password") or
die ("Could not connect:". Mysql_error ());
mysql_select_db ("MyDB");
$result = mysql_query ("SELECT ID, name from mytable");
while (Row=mysqlfetcharray (result, Mysql_assoc)) {
printf ("ID:%s Name:%s", row["id"],row["name");
}
Mysql_free_result ($result);

35, GD Library is what to do with? (1 points)

Dynamic Open Image Processing library

36, point out some of the PHP input a section of HTML code method. (1 points)

echo "{html}"
echo <<eod
{html}
EOD;

37. Which of the following functions can open a file for read and write operations? (1 points) c
(a) Fget () (b) File_open () (c) fopen () (d) Open_file ()

38. Which of the following options does not add John to the users array? (1 points) b
(a) $users [] = ' John ';
(b) Array_add ($users, ' John ');
(c) Array_push ($users, ' John ');
(d) $users | | = ' John ';

39, the following program will enter whether? (1 points) 10

$num = ten;
function Multiply () {
num=num *;
}
Multiply ();
echo $num;
? >

40, use PHP to write a simple query to find all the names of "John" content and print out (2 points)
Table name UserName Tel Content Date
313,333,663,366 College graduate 2006-10-11
313,612,312,331 Graduate 2006-10-15
Zhang Four 021-55665566 secondary school graduation 2006-10-15
Please complete the code according to the above topic:

$mysql _db=mysql_connect ("local", "Root", "pass");
@mysql_select_db ("db", $mysql _db);
$sql = sprintf ("Select * from%s where UserName = '%s '", 
 "table name", 
 "John");
Values=mysqlquery (SQL);
while (Item=mysqlfetchqueryarray values)
{
 echo sprintf ("Username:%s, phone%s, education:%s, Graduation Date:%s", 
 item[' UserName '],item[' Tel '], item[' Content '],item[' Date '
 );
}

41, how to use the following class, and explain what the following meaning? (3)

Class test{
function Get_test ($num) {
num=md5 MD5 (num). En ");
return $num;
}
$test = new test ();
Ret=test->get_test (one);
Print_r ($ret); exit;

The 32-bit string generated after the NUM is MD5 encoded A1 and "En" are contacted and then MD5 encoded again

42, write out the format of SQL statements: INSERT, UPDATE, delete (4 points)
Table name UserName Tel Content Date
313,333,663,366 College graduate 2006-10-11
313,612,312,331 Graduate 2006-10-15
Zhang Four 021-55665566 secondary school graduation 2006-10-15
(a) A new record (Xiao Wang 13254748547 High school graduation 2007-05-06) please add the SQL statement to the table
Insert into table name values (' Xiao Wang ', ' 13254748547 ', ' High school graduation ', ' 2007-05-06 ')
(b) Use SQL statements to make the John time update the current system time
Update table name Set Date = GETDATE () where UserName = "John"
(c) Please write out the deletion of all records named Zhang Xi
Delete from indicates where UserName = "Zhang Si"

43. Please write out the meaning of the data type (int char varchar datetime text); What difference does varchar and char have (2 points)
int integral type
char Storage fixed length
varchar storage becomes longer
DateTime time
The text store becomes longer
varchar is getting longer
CHAR (20) fixed length

44. The mysq type (usually the table ID field) must be set to (?) Field (1 points)
Auto_increment
45. Write out the output of the following program (1 points)

$b =201;
$c =40;
a=b> $c 4:5;
echo $a;

46, to detect whether a variable has a set of functions whether or not the function is empty? (2 points)
Isset ()
Empty ()

47. What is the function to get the total number of query result sets? (1 points)

Mysql_num_rows ()

48, $arr = Array (' James ', ' Tom ', ' Symfony '); Please print out the value of the first element (1 points)

Print_r ($arr [0]);
Reset ($arr);
Print_r (current ($arr));
Print_r (Array_shift ($arr));

49, please divide the value of the array of 41 with ', ' number and merge into the string output (1 points)
Implode

50, a= ' abcdef '; Please remove the value of a and print out the first letter (1 points)

$a [0];
substr ($a, 0, 1);

51, PHP can and SQL Server/oracle database connection? (1 points)
OK
There's a ready-made library.

52, please write the PHP5 permission control modifier (3 points)
Public
Private
Protected

53, please write the PhP5 constructor and destructor (2 points)

Public function __construct ()
{
} public
function __destruct ()
{
}

Programming Questions:

1. Write a function, as efficiently as possible, to remove the file extension from a standard URL
For example: http://www.sina.com.cn/abc/de/fg.php?id=1 need to remove PHP or. php

<?php
$url = "http://www.sina.com.cn/abc/de/fg.php?id=1";
Arr=parseurl (URL);
Patharr=pathinfo (arr[' path '));
Print_r ($pathArr [' extension ']);

3. Write a function to calculate the relative path of two files
If $a = '/a/b/c/d/e.php ';
$b = '/a/b/12/34/c.php ';
Calculated b Relative to a relative path should be http://www.jb51.net/12/34/c.php will be added

<?php
$a = '/a/b/c/d/e.php ';
$b = '/a/b/12/34/c.php ';
Gets the relative path
function Sgetrelativepath (path,conpath)
{
 Patharr=explode ("/", path)
 of path relative to Conpath; Conpatharr=explode ("/", Conpath);
 $dismatchlen = 0;
 For (I=0;i < count (Patharr); i++)
 {
 if (conpatharr[i)!= patharr[i])
 {
  Dismatchlen=count ( Patharr)-$i;
  Arrleft=arrayslice (Patharr, $i);
  break;
 }
 }
 Ret=strrepeat (".. /", Dismatchlen). Implode ("/", $arrLeft);
 return $ret;
}
Print_r (Sgetrelativepath (b,a));

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

<?php
function Agetallfile ($folder)
{
 $aFileArr = array ();
 if (Is_dir ($folder))
 {
 Handle=opendir (folder);
 while ((File=readdir (handle))!== false)
 {
  //if it is. Or. The
  if (file==) is skipped. File = = "...")
  {
  continue;
  }
  if (Is_file (folder.) /". File)"
  {
  afilearr[]=file; 
  }
  else if (Is_dir (folder.) /". File)
  " {
  afilearr[file] = agetallfile (folder.) /". file);
  }
 Closedir ($handle);
 return $AFILEARR;
}
$path = "/home/test/sql";
Print_r (Agetallfile ($path));

I hope this article will help you with your PHP program design.

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.