Common php functions (2)

Source: Internet
Author: User

/**
* Read cache. The default value is File Cache. The cache configuration is not loaded.
* @ Param string $ name cache name
* @ Param $ filepath: data path (Module name) caches/cache _ $ filepath/
* @ Param string $ config configuration name
*/
Function getcacheinfo ($ name, $ filepath = '', $ type = 'file', $ config = ''){
Pc_base: load_sys_class ('cache _ factory ');
If ($ config ){
$ Cacheconfig = pc_base: load_config ('cache ');
$ Cache = cache_factory: get_instance ($ cacheconfig)-> get_cache ($ config );
} Else {
$ Cache = cache_factory: get_instance ()-> get_cache ($ type );
}
Return $ cache-> cacheinfo ($ name, '','', $ filepath );
}
 
/**
* Generate an SQL statement. If $ in_cloumn is input, the generated format is IN ('A', 'B', 'C ')
* @ Param $ data condition array or string
* @ Param $ front connector
* @ Param $ in_column field name
* @ Return string
*/
Function to_sqls ($ data, $ front = 'and', $ in_column = false ){
If ($ in_column & is_array ($ data )){
$ Ids = '\ ''. implode (' \ ', \'', $ data ).'\'';
$ SQL = "$ in_column IN ($ ids )";
Return $ SQL;
} Else {
If ($ front = ''){
$ Front = 'and ';
}
If (is_array ($ data) & count ($ data)> 0 ){
$ SQL = '';
Foreach ($ data as $ key => $ val ){
$ SQL. = $ SQL? "$ Front '$ key' =' $ val '": "' $ key' = '$ val '";
}
Return $ SQL;
} Else {
Return $ data;
}
}
}
 
/**
* Paging Functions
*
* @ Param $ num Total Information
* @ Param $ curr_page current page
* @ Param $ perpage
* @ Param $ urlrule URL rule
* @ Param $ array the array to be passed, used to add additional methods
* @ Return Paging
*/
Function pages ($ num, $ curr_page, $ perpage = 20, $ urlrule = '', $ array = array (), $ setpages = 10 ){
If (defined ('urlrule') & $ URLRULE = ''){
$ Urlrule = URLRULE;
$ Array = $ GLOBALS ['url _ array'];
} Elseif ($ urlrule = ''){
$ Urlrule = url_par ('page = {$ page }');
}
$ Multipage = '';
If ($ num> $ perpage ){
$ Page = $ setpages + 1;
$ Offset = ceil ($ setpages/2-1 );
$ Pages = ceil ($ num/$ perpage );
If (defined ('in _ admin ')&&! Defined ('pages ') define ('pages', $ PAGES );
$ From = $ curr_page-$ offset;
$ To = $ curr_page + $ offset;
$ More = 0;
If ($ page >=$ pages ){
$ From = 2;
$ To = $ pages-1;
} Else {
If ($ from <= 1 ){
$ To = $ page-1;
$ From = 2;
} Elseif ($ to >=$ pages ){
$ From = $ pages-($ page-2 );
$ To = $ pages-1;
}
$ More = 1;
}
$ Multipage. = '<a class = "a1">'. $ num. L ('page _ item'). '</a> ';
If ($ curr_page> 0 ){
$ Multipage. = '<a href = "'. pageurl ($ urlrule, $ curr_page-1, $ array ). '"class =" a1 "> '. L ('previous '). '</a> ';
If ($ curr_page = 1 ){
$ Multipage. = '<span> 1 </span> ';
} Elseif ($ curr_page> 6 & $ more ){
$ Multipage. = '<a href = "'. pageurl ($ urlrule, 1, $ array). '"> 1 </a> ..';
} Else {
$ Multipage. = '<a href = "'. pageurl ($ urlrule, 1, $ array). '"> 1 </a> ';
}
}
For ($ I = $ from; $ I <= $ to; $ I ++ ){
If ($ I! = $ Curr_page ){
$ Multipage. = '<a href = "'. pageurl ($ urlrule, $ I, $ array). '">'. $ I. '</a> ';
} Else {
$ Multipage. = '<span>'. $ I. '</span> ';
}
}
If ($ curr_page <$ pages ){
If ($ curr_page <$ pages-5 & $ more ){
$ Multipage. = '.. <a href = "'. pageurl ($ urlrule, $ pages, $ array ). '"> '. $ pages. '</a> <a href = "'. pageurl ($ urlrule, $ curr_page + 1, $ array ). '"class =" a1 "> '. L ('Next '). '</a> ';
} Else {
$ Multipage. = '<a href = "'. pageurl ($ urlrule, $ pages, $ array ). '"> '. $ pages. '</a> <a href = "'. pageurl ($ urlrule, $ curr_page + 1, $ array ). '"class =" a1 "> '. L ('Next '). '</a> ';
}
} Elseif ($ curr_page = $ pages ){
$ Multipage. = '<span> '. $ pages. '</span> <a href = "'. pageurl ($ urlrule, $ curr_page, $ array ). '"class =" a1 "> '. L ('Next '). '</a> ';
} Else {
$ Multipage. = '<a href = "'. pageurl ($ urlrule, $ pages, $ array ). '"> '. $ pages. '</a> <a href = "'. pageurl ($ urlrule, $ curr_page + 1, $ array ). '"class =" a1 "> '. L ('Next '). '</a> ';
}
}
Return $ multipage;
}

From chaojie2009

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.