PHP Sina interview questions and complete answers

Source: Internet
Author: User
Tags php regular expression
I am bored to find a set of Sina PHP pen questions. I have completed the questions in the case of a manual. You are welcome to make a brick. I am not enough to move the bricks for you... Thank you for your advice! 1. write a function to be as efficient as possible. extract the text from a Standard & amp; nbsp; url & amp; nbsp;

I am bored to find a set of Sina PHP pen questions. I have completed the questions in the case of a manual. You are welcome to make a brick. I am not enough to move the bricks for you... Thank you for your advice!

1. write a function to retrieve the file extension from a standard url as efficiently as possible.
Example: http://www.phpddt.com/abc/de/fg.php? Id = 1 need to retrieve php or. php

A: I did this directly using PHP built-in functions without repeating the wheel. it is estimated that the author also wants to evaluate the basic knowledge, mainly to parse the url and a function that returns the file information (extension: multiple methods for getting the file suffix ):


 

2. in HTML, the meta tag in the page header can be used to output the file encoding format. The following is a standard meta statement.

Use the PHP language to write a function and change the charset part of a standard HTML page similar to meta tag to big5.
Note:
(1) the complete html page must be processed, that is, not only this meta statement
(2) case insensitive
(3) 'and "here are interchangeable
(4) the quotation marks on both sides of 'content-type' can be ignored, but the quotation marks on both sides of 'text/html; charset = gbk' cannot.
(5) handle extra spaces

A: I forgot the regular expression (PHP regular expression details) for about half a day.


 "; // Match the standard meta tag $ pattern = "/
 
  
/I "; $ replacement ="
  "; $ Result = preg_replace ($ pattern, $ replacement, $ html); echo htmlspecialchars ($ result);?>
 


3. write a function to calculate the relative path of the two files.
For example, $ a = '/a/B/c/d/e. php ';
$ B = '/a/B/12/34/c. php ';
Calculate the relative path of $ B relative to $ a./../c/d to add ().

Answer:


 

4. write a function to traverse all files and subfolders in a folder.

A: I wrote this in my blog (php file traversal and file copy), but there are many implementation methods and the efficiency is not necessarily the highest.


/* *@blog  http://www.phpddt.com */function listDir($dir = '.'){if ($handle = opendir($dir)) {while (false !== ($file = readdir($handle))) {if($file == '.' || $file == '..'){continue;}if(is_dir($sub_dir = realpath($dir.'/'.$file))){echo 'FILE in PATH:'.$dir.':'.$file.'
';listDir($sub_dir);}else{echo 'FILE:'.$file.'
';}}closedir($handle);}} listDir('e:\www\abc');

5. briefly describe the implementation principles of unlimited classification in the forum.

A: The Infinitus classification should be a recursive function!

Step 1: Create a test database:


 CREATE TABLE `category` (  `id` smallint(5) unsigned NOT NULL auto_increment,  `fid` smallint(5) unsigned NOT NULL default '0',  `value` varchar(50) NOT NULL default '',  PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Step 2: insert test data:


Insert into 'category '('fid', 'value') VALUES (0, 'php point-to-point blog PHPDDT. COM '), (1, 'A'), (1,' B '), (2, 'C'), (2, 'D'), (4, 'E ')

Step 3: recursive output classification:


 "; GetCate ($ arr [$ I] [0]); // recursion }}?>


6. design a webpage so that a full screen window is displayed when it is opened, which contains a text box and a button. After entering information in the text box, you can click the button to close the window. the entered information is displayed on the main page!

Answer: Nima. I don't know what the problem is. have Sina engineers gotten into the water? Evaluate the knowledge of js window objects? Tell me?

Index.html


            By www.phpddt.com    

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.