Advertisement
jargon

Fast_Cat

Apr 14th, 2022
1,340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.24 KB | None | 0 0
  1. <?php
  2.  
  3. function fast_cat( $path = '', $ext = array(), $include_folders = false )
  4. {
  5.     global $nen;
  6.  
  7.     if( is_string( $ext ) )
  8.     {
  9.         $ext = array( 0 => $ext );
  10.     }
  11.     if( ( !is_array( $ext ) ) | ( $ext === array() ) )
  12.     {
  13.         $ext = array( 0 => '' );
  14.     }
  15.    
  16.     if( $include_folders !== false )
  17.     {
  18.         $buffer = ( is_dir( $_SERVER[ 'DOCUMENT_ROOT' ] . '/' . $path ) ? array_diff( scandir( $_SERVER[ 'DOCUMENT_ROOT' ] . '/' . $path, SCANDIR_SORT_ASCENDING ), array( '..', '.' ) ) : array() );
  19.     }
  20.     else
  21.     {
  22.         $buffer = ( is_dir( $_SERVER[ 'DOCUMENT_ROOT' ] . '/' . $path ) ? array_diff( scandir( $_SERVER[ 'DOCUMENT_ROOT' ] . '/' . $path, SCANDIR_SORT_ASCENDING ), array( '..', '.' ) ) : array() );
  23.     }
  24.    
  25.     $cat = array();
  26.    
  27.     foreach( $buffer as $entry )
  28.     {
  29.         $hit = 0;
  30.         foreach( $ext as $test )
  31.         {
  32.        
  33.             if( strtolower( substr( $entry, -strlen( $test ), strlen( $test ) ) ) === strtolower( $test ) )
  34.             {
  35.                 $hit++;
  36.                 break;
  37.             }
  38.         }
  39.         if( $hit > 0 )
  40.         {
  41.             $cat[ count( $cat ) ] = $entry;
  42.         }
  43.     }
  44.  
  45.     natcasesort( $cat );
  46.     $cat = array_values( $cat );
  47.        
  48.     return $cat;
  49. }
  50.  
  51. function cat_rando( $cat )
  52. {
  53.     global $nen;
  54.  
  55.     if( count( $cat ) > 0 )
  56.     {
  57.         return $cat[ rand( 0, count( $cat ) - 1 ) ];
  58.     }
  59.     else
  60.     {
  61.         return '';
  62.     }
  63. }
  64.  
  65. ?>
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement