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!