PHP side Question Two

Source: Internet
Author: User
Tags array sort echo date php class php print print format

1, crawl the remote image to the local, you will use what function?

Fsockopen, A

2. Write a function that asks for the maximum value of 3 with the least amount of code.

function ($a, $b, $c) {
* W0 z* U6 k + E. L A:}5} return $a > $b? ($a > $c? $a: $c): ($b > $c? $b: $c);
5 O:f6 v1 w# U}

3, in PHP print out the day before, the print format is May 10, 2007 22:21:21

Echo date (' y-m-d h:i:s ', Strtotime ('-1 day '));

4, JavaScript can define a two-dimensional array, if not you how to solve?

JavaScript does not support two-dimensional array definitions and can be resolved with arr[0] = new Array ()

5, assume that a.html and b.html under the same folder, with JavaScript implementation when the a.html opened for five seconds, automatically jump to b.html.


function go2b () {    window. location = "B.html";    Window. close ();}
SetTimeout ("go2b ()", 5000); Auto-execute go2b after 5 seconds ()

6,//Is browsing the current page user's IP address: 127.0.0.1
echo $_server["REMOTE_ADDR"]. "
”;
(query) string (the first question mark in the URL?) Later content): id=1&bi=2
echo $_server["Query_string"]. "
”;
The document root directory where the currently running script is located: D:inetpubwwwroot
echo $_server["Document_root"]. "
”;
7, in HTTP 1.0, the meaning of status Code 401 is not authorized ____; If you return the prompt "file not found", the header function is available, and the statement is the header ("http/1.0 404 Not Found");

401 means not authorized;  Header ("http/1.0 404 Not Found");

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

<?PHPfunctionMy_dir ($dir){         $files=Array(); //Note that there is a @, or there will be warning error message         if(@$handle=Opendir($dir)){                           while(($file=Readdir($handle))!==false){                 //exclude root directory;                 if($file! = "." &&$file!="."){                                     //if it is a subfolder, it is recursive, not the name of the file is stored in the array;                     if(Is_dir($dir." /".$file)){                         $files[$file]=my_dir ($dir." /".$file); }Else{                         $files[]=$file; }                   }             }             Closedir($handle); return $files; }     }    //here is the test     $array=my_dir (' C:/test '); Var_dump($array);

9. Add John to the users array?

$users [] = ' join ';   
Array_push ($users, ' John ');

10. What is the function of error_reporting in PHP?
Answer: error_reporting () sets the error level of PHP and returns the current level.
11. Use regular Expressions (Regular expression) to write a function to verify that the e-mail message is in the correct format.

<? PHP $email=$_post[' email ']; if (! Preg_match ('/^[\w. ') [Email protected] ([\w.] +)\. [A-z] {2,6}$/i ',$email))  {    echo ' e-mail detection failed ';} Else {    echo ' e-mail detection succeeded ';}

13, how to modify the duration of the session (1 points).

Answer: Method 1: Set session.gc_maxlifetime in php.ini to 9999 restart Apache

Method 2: $savePath = "./session_save_dir/";

$lifeTime = hour * SECOND;

Session_save_path ($savePath);

Session_set_cookie_params ($lifeTime);

Session_Start ();

Method 3:setcookie () and Session_set_cookie_params ($lifeTime);

 

14, there is a Web page address, such as the PHP Development Resource Network Home page: http://www.phpres.com/index.html, how to get its content?
Echo file_get_contents ("http://www.phpres.com/index.html");

15, please explain the difference between the value and the reference in PHP. When is the value passed? (2 points)

A: Any change to a value in the scope of a function is ignored outside of the function

is passed by reference: any changes to values within the function can also reflect these modifications

Pros and Cons: When passing by value, PHP must copy the value. This can be a costly operation, especially for large strings and objects.

Passing by reference does not require copying values, which is good for performance gains.

 

16, write a function, as efficiently as possible, 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  function  getext ( $url    $arr  = parse_url     ( $url    $file  = basename  ( $arr  [' Path '   $ext  = explode  (".",  $file   return   $ext  [1 ];}   

17, use more than five ways to get a file extension

Requirements: dir/upload.image.jpg, find. jpg or JPG,
Must be handled using PHP's own processing function, which cannot be significantly duplicated and can be encapsulated into functions such as GET_EXT1 ($file _name), get_ext2 ($file _name)

functionGET_EXT1 ($file _name){    return STRRCHR($file _name, ‘.');}functionGET_EXT2 ($file _name){    return substr($file _name,Strrpos($file _name, ‘.'));functionGET_EXT3 ($file _name){    return Array_pop(Explode(‘.’,$file _name));}functionGET_EXT4 ($file _name){    $p=PathInfo($file _name); return $p[' extension '];}functionGET_EXT5 ($file _name){    return Strrev(substr(Strrev($file _name), 0,Strpos(Strrev($file _name), ‘.' ));18, <?php$str1 = null; $str 2 = false;

echo $str 1== $str 2?     ' Equal ': ' Not equal '; Equal

$str 3 = ";
$str 4 = 0;
Echo $str 3== $str 4?      ' Equal ': ' Not equal '; Equal

$str 5 = 0;
$str 6 = ' 0′;
echo $str 5=== $str 6?    ' Equal ': ' Not equal '; Not equal

19. What is the main difference between a field type varchar and char in a MySQL database? That field is more efficient to find, why?
VARCHAR is a variable length, saving storage space, char is fixed. Find efficiency: Char type is fast, because varchar is a non-fixed length, you must first look for the length, then extract the data, a step more than the char fixed length type, so less efficient

20. Use JavaScript to write out three ways to produce an image tag (hint: From method, object, HTML angle)
(1) var img = new Image ();
(2) var img = Document.createelementbyid ("image")
(3) img.innerhtml = ""

21, 16. Please describe the most significant difference between XHTML and HTML over two points
(1) XHTML must force the specified document type doctype,html not required
(2) XHTML All tags must be closed, HTML is more casual

22, write a sorting algorithm, can be a bubble sort or a quick sort, assuming the object to be sorted is a dimensional array.

Bubble sort (Array sort)
function Bubble_sort ($array)
{
$count = count ($array);
if ($count <= 0) return false;
for ($i =0; $i < $count; $i + +) {
for ($j = $count-1; $j > $i; $j –) {
if ($array [$j] < $array [$j-1]) {
$tmp = $array [$j];
$array [$j] = $array [$j-1];
$array [$j-1] = $tmp;
}
}
}
return $array;
}
Quick sort (Array sort)
function Quicksort ($array) {
if (count ($array) <= 1) return $array;
$key = $array [0];
$left _arr = Array ();
$right _arr = Array ();
for ($i =1; $i <count ($array); $i + +) {
if ($array [$i] <= $key)
$left _arr[] = $array [$i];
Else
$right _arr[] = $array [$i];
}
$left _arr = quicksort ($left _arr);
$right _arr = quicksort ($right _arr);
Return Array_merge ($left _arr, Array ($key), $right _arr);
}



23, write out three kinds of MySQL database storage engine name (hint: case-insensitive)
MyISAM, InnoDB, BDB (Berkeley DB), Merge, Memory (Heap), Example, Federated, Archive, CSV, blackhole, MaxDB, etc. more than 10 engines

24, the difference of two dates, for example, 2007-2-5 ~ 2007-3-6 Date Differential
Method One:
<?php
Class Dtime
{
function Get_days ($date 1, $date 2)
{
$time 1 = strtotime ($date 1);
$time 2 = strtotime ($date 2);
Return ($time 2-$time 1)/86400;
}
}
$Dtime = new Dtime;
echo $Dtime->get_days (' 2007-2-5′, ' 2007-3-6′);
?>
Method Two:
<?php
$temp = Explode ('-', ' 2007-2-5′ ');
$time 1 = mktime (0, 0, 0, $temp [1], $temp [2], $temp [0]);
$temp = Explode ('-', ' 2007-3-6′ ');
$time 2 = mktime (0, 0, 0, $temp [1], $temp [2], $temp [0]);
Echo ($time 2-$time 1)/86400;
Method Three: Echo ABS (Strtotime ("2007-2-1″)-strtotime (" 2007-3-1″) "/60/60/24 Calculate time difference



25, write a function to achieve the following functions: the string "Open_door" converted to "Opendoor", "make_by_id" to convert to "Makebyid".

//Method OnefunctionStr_explode ($str){    $str _arr=Explode("_",$str); $str _implode=implode(" ",$str _arr); $str _implode=implode("",Explode("",Ucwords($str _implode))); return $str _implode;}$strexplode=Str_explode ("make_by_id");Print_r($strexplode);//Method Two$str= "make_by_id!";$expStr=Explode("_",$str); for($i= 0;$i<Count($expStr);$i++) {Echo Ucwords($expStr[$i]);}//Method ThreeEcho Str_replace(‘ ‘,”,Ucwords(Str_replace(' _ ', ' ', ' Open_door '));

26, the ID of a table has multiple records, the record of all this ID, and show the total number of records, with SQL statements and views,
Stored procedures are implemented separately.
DELIMITER//
CREATE PROCEDURE Proc_countnum (in columnId int,out Rowsno int)
Begin
Select COUNT (*) into Rowsno from member where Member_id=columnid;
End
Call Proc_countnum (1, @no);
Select @no;
Method: View:
CREATE View V_countnum as Select Member_id,count (*) as Countnum from member group by
member_id
Select Countnum from V_countnum where member_id=1



27, JS in the page forward and backward code

Forward: History.forward (); =history.go (1);

Back: History.back (); =history.go (-1); )

28, Echo Count ("abc"); Output what?
Answer: 1

count-count the number of cells in an array or the number of properties in an object

int count (mixed$var [, int $mode]), if Var is not an array type or an object that implements the countable interface, returns 1, with one exception, if Var is NULL then the result is 0.

For an object, if SPL is installed, you can invoke count () by implementing the countable interface. The interface has only one method count (), and this method returns the return value of the count () function.



29, there is a one-dimensional array, which stores shaping data, please write a function, they are in order from large to small. Requires high efficiency of execution. and explain how to improve the efficiency of execution. (The function must be implemented by itself and cannot use PHP functions)

<?php
Function Bubblesort (& $arr)
{
$cnt =count ($arr);
$flag = 1;
for ($i =0; $i < $cnt; $i + +)
{
if ($flag ==0)
{
Return
}
$flag = 0;
for ($j =0; $j < $cnt-$i-1; $j + +)
{
if ($arr [$j]> $arr [$j +1])
{
$tmp = $arr [$j];
$arr [$j]= $arr [$j +1];
$arr [$j +1]= $tmp;
$flag = 1;
}
}
}
}
$test =array (1,3,6,8,2,7);
Bubblesort ($test);
Var_dump ($test);
?>

30, please give an example of how to use in your development process to speed up the page loading speed
A: To use the server resources to open, timely shut down the server resources, database Add index, the page can generate static, pictures and other large files separate server. Using the Code optimization tool
31. What does the following code produce?

  $num  = 10;  function   multiply () {  $num  =  $num  * 10;} Multiply ();  echo   $num ; 

The value of the $num is 10 because the function multiply () does not specify $num to be a global variable (for example, $num or $_globals[' num ').



What is the difference between static,public,private,protected in PHP class?

Static statically, the class name can be accessed

Public represents the global, and the inner and outer subclasses of the class can be accessed;

Private means that only this class can be used internally;

Protected is protected and is accessible only in this class or subclass or in the parent class;



What is the difference between get, post, and head in the HTTP protocol?

HEAD: Only the header of the page is requested.

GET: Requests the specified page information and returns the entity principal.

POST: The requesting server accepts the specified document as a new subordinate entity for the identified URI.

(1) HTTP defines different ways to interact with the server, with the most basic approach being GET and POST. In fact GET applies to most requests, while retaining POST is only used to update the site.

(2) When the form is submitted, if you do not specify method, the default is a GET request, the data submitted in the form will be appended to the URL, separated from the URL. The alphanumeric character is sent as is, but the space is converted to the "+" sign, and the other symbol is converted to%XX, where XX is the ASCII (or ISO Latin-1) value that the symbol is represented in 16 binary. The GET request submits the data to be placed in the HTTP request protocol header, and the data submitted by the post is placed in the Entity data;

The Get method submits only 1024 bytes of data, while Post does not have this limit.

(3) GET This is the most common method that the browser uses to request the server. Post This method is also used to transfer data, but unlike get, when using post, the data is not appended to the URI, but rather as a separate line to pass, at this time must also send a CONTENT_LENGTH title to indicate the length of the data, followed by a blank line, Then the data is actually transferred. Web forms are usually sent by post.

PHP side Question Two

Related Article

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.