PHP technician-oral summary PHP

Source: Internet
Author: User
PHP technician-interview summary PHP article 1. enable the mbstring extension to achieve Chinese string truncation without garbled characters, and then customize the function: & lt ;? Phpheader ('content-Type: text/html: charset = utf-8 '); functionsubstr_utf8 ($ str, $ start, $ length PHP technician-interview summary for PHP
1. implementation Chinese string truncationMethod without garbled characters
Enable the mbstring extension and then customize the function:

 

2. use PHP to print the previous day


  

3. it is not applicable to the third variable to exchange the values of two variables.


   

4. convert 1234567890 to 1,234,567,890


Header ('content-Type: text/html: charset = utf-8 '); $ str = '000000'; // reverse string $ str = strrev ($ str ); // use commas to separate 098,765,432, 1, $ str = chunk_split ($ str, 3, ','); // reverse $ str = strrev ($ str) again ); // remove the left, $ str = ltrim ($ str, ','); echo $ str;


5. utf8 string inversion
Strrev cannot be used. errors may occur in Chinese.


Function strrev_utf8 ($ str) {return join ("", array_reverse (preg_split ("// u", $ str )));} $ str = "I am a good boy"; echo strrev_utf8 ($ str); 6. get the url file extension, try to implement as many methods as possible $ str = "www.baidu.com/index.php "; function get_ext1 ($ str) {return strrchr ($ str ,'. ');} function get_ext2 ($ str) {return substr ($ str, strrpos ($ str ,'. ');} function get_ext3 ($ str) {$ str = pathinfo ($ str); return $ str ['extension'];} function get_ext4 ($ str) {$ arr = explode ('. ', $ str); return $ arr [count ($ arr)-1];} function get_ext5 ($ str) {$ pattern ='/^ [^ \.] + \. ([\ w] +) $/'; return preg_replace ($ pattern,' $ {1} ', basename ($ str ));}


7. write a function to convert the string open_door to OpenDoor.


$str = "open_door";function change_str($str){$arr = explode('_',$str);$arr = array_map('ucfirst',$arr);return implode('',$arr);}echo change_str($str);


8. Singleton mode


    

10. get the file extension from a completed url


     

11. writing a function facilitates all files and subfolders in a folder.
      

12. unlimited classification implementation principles in the forum
First, design the database table


Create table category (cate_id int unsigned not null auto_increment primary key, cat_name varchar (30) not null default '', parent_id int unsigned not null default 0) engine = innodb charset = utf8; then implement it recursively using the function. the function tree ($ arr, $ pid = 0, $ level = 0) {static $ list = array (); foreach ($ arr as $ v) {// if it is a top-level classification, save $ list // and use this node as the root point, traverse its subnode if ($ v ['parent _ id'] =pid pid) {$ v ['level'] = $ level; $ list [] = $ v; tree ($ arr, $ v ['cat _ id'], $ level + 1) ;}} return $ list ;}


13. calculate the relative path of the two files
       1) {$ I + = 1; $ head = array_shift ($ monkey); // if ($ I % $ m! = 0) {// if it is not a multiple of m, the end is returned; otherwise, array_push ($ monkey, $ head); }} return $ monkey [0];} is listed. echo king (10, 7 );


15. PHP implements two-way queue
       queue,$item);}public function addLast($item){return array_push($this->queue,$item);}public function getFirst(){return array_shift($this->queue);}public function getLast(){return array_pop($this->queue);}} 

Hope this articlePhp developersThanks for reading this 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.