I would like to share with you several common PHP functions.

Source: Internet
Author: User

I would like to share with you several common PHP functions.

It's about 20 minutes before work. I have nothing to do with it. I 'd like to share some functions with you. Super easy to use!

Truncates string functions.

/*** @ Param string $ begin start string * @ param string $ end string * @ param string $ str string to be intercepted * @ return string */function get_str ($ begin, $ end, $ str) {$ B = mb_strpos ($ str, $ begin) + mb_strlen ($ begin); $ e = mb_strpos ($ str, $ end)-$ B; return mb_substr ($ str, $ B, $ e );}

This is a very useful function for intercepting strings. html code is used. Use the strip_tags () function to convert the code into a string!

Curl encapsulation Function

function curlGet($url) {     $ch = curl_init();     curl_setopt($ch, CURLOPT_URL, $url);     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);      curl_setopt($ch, CURLOPT_HEADER, true);     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);         return curl_exec($ch); }

Anyone who has written Curl knows that it is always necessary to write a lot of data before it can be used. Now, the blogger has encapsulated it for you and used it. The parameter should also be known by pig, so it will not be marked!

CATEGORY tree functionCan be used for classification and hierarchical relationship with message boards.

/*** Define the category tree function * @ param items the two-dimensional array to be classified * @ param $ id Primary Key (unique ID) * @ param $ belong_id: id of the primary key associated with the PID * @ son can be customized to insert into it */function catagory ($ items, $ id = 'id ', $ belong_id = 'belong _ id', $ son = 'children ') {$ tree = array (); // formatted tree $ tmpMap = array (); // temporary flat data foreach ($ items as $ item) {$ tmpMap [$ item [$ id] = $ item;} foreach ($ items as $ item) {if (isset ($ tmpMap [$ item [$ belong_id]) {$ tmpMap [$ item [$ belong_id] [$ son] [] = & $ tmpMap [$ item [$ id];} else {$ tree [] = & $ tmpMap [$ item [$ id] ;}} unset ($ tmpMap); return $ tree ;}

Okay ~ The blogger is playing football after work ~

Bye, see you!

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.