![]()
Snippets of A |
|
|
What are snippets? |
|
function scanDirectory($node, $limit=0, $separator="\"){ //validate: if(!is_dir($node)){return null;}; $newSeparator=($separator=="\")?"/":$separator; $node=str_replace($separator,$newSeparator,$node); $node=str_replace("//",$newSeparator,$node); $node=(strrpos($node, $newSeparator)==strlen($node)-1)? substr($node, 0, strlen($node)-1):$node; //initialize: $slashes=substr_count($node, $newSeparator); $limit=(!$limit)?-1:$limit+$slashes; $stack=array( array($node, $slashes) ); $directories=array(); $files=array(); $output=array(); //RUN: while(sizeof($stack) && $stack[0][1]!=$limit){ $current=array_shift($stack); $items=opendir($current[0]); while( ($it=readdir($items))!==false ){ if( strrpos($it,".") === (strlen($it)-1) ){continue;}; $path=$current[0].$newSeparator.$it; $output[]=$path; if(is_dir($path)){ $directories[]=$path; $stack[]=array( $path, substr_count($path, $newSeparator) );} else{$files[]=$path;}; }; } return array($output, $directories, $files); /* keep this comment to reuse freely: http://www.fullposter.com/?1 */}Remove colors
function scanArray($node){ if(!$node || !is_array($node)){return null;}; $output=array(); $stack=array( array($node, sizeof($node), 0, array()) ); while(sizeof($stack)){ $currentStackIndex=sizeof($stack)-1; if(is_array( $stack[$currentStackIndex][0] ) && $stack[$currentStackIndex][1]){ $nextObjectIndex=( sizeof($stack[$currentStackIndex][0]) - $stack[$currentStackIndex][1] ); --$stack[$currentStackIndex][1]; $stack[$currentStackIndex][2]=1; array_push($stack, array($stack[$currentStackIndex][0][$nextObjectIndex], sizeof($stack[$currentStackIndex][0][$nextObjectIndex]), 0, array_merge($stack[$currentStackIndex][3], array($nextObjectIndex))) ); continue;}; if( !$stack[$currentStackIndex][2] ){ $output[]=array($stack[$currentStackIndex][0], $stack[$currentStackIndex][3]); }; array_pop($stack); } return $output; /* keep this comment to reuse freely: http://www.fullposter.com/?1 */}Remove colors
function scanAssociative($node){ if(!$node || !is_array($node)){return null;}; $output=array(); $stack=array( array($node, 0, 0, 0, array(), array(), array()) ); while(sizeof($stack)){ $currentStackIndex=sizeof($stack)-1; if( !$stack[$currentStackIndex][2] && is_array($stack[$currentStackIndex][0]) ){ $stack[$currentStackIndex][4]=array_keys($stack[$currentStackIndex][0]); $stack[$currentStackIndex][1]=sizeof($stack[$currentStackIndex][4]);/*decreasing length*/ $stack[$currentStackIndex][2]=sizeof($stack[$currentStackIndex][4]);/*fixed length*/ }; if(is_array( $stack[$currentStackIndex][0] ) && $stack[$currentStackIndex][1]){ $nextObjectIndex=( $stack[$currentStackIndex][2] - $stack[$currentStackIndex][1] ); $nextObjectAssociativeIndex=$stack[$currentStackIndex][4][$nextObjectIndex]; --$stack[$currentStackIndex][1]; $stack[$currentStackIndex][3]=1; array_push($stack, array($stack[$currentStackIndex][0][$nextObjectAssociativeIndex], 0, 0, 0, array(), array_merge($stack[$currentStackIndex][5], array($nextObjectAssociativeIndex)), array_merge($stack[$currentStackIndex][6], array($nextObjectIndex)) ) ); continue;}; if( !$stack[$currentStackIndex][3] ){ $output[]=array($stack[$currentStackIndex][0], $stack[$currentStackIndex][5], $stack[$currentStackIndex][6]); }; array_pop($stack); } return $output; /* keep this comment to reuse freely: http://www.fullposter.com/?1 */}Remove colors
function scanArrayAll($node){ if(!$node || !is_array($node)){return null;}; $output=array(); $stack=array( array($node, sizeof($node), 0, array()) ); while(sizeof($stack)){ $currentStackIndex=sizeof($stack)-1; if(is_array( $stack[$currentStackIndex][0] ) && $stack[$currentStackIndex][1]){ if(!$stack[$currentStackIndex][2]){ $output[]=array($stack[$currentStackIndex][0], $stack[$currentStackIndex][3]); }; $nextObjectIndex=( sizeof($stack[$currentStackIndex][0]) - $stack[$currentStackIndex][1] ); --$stack[$currentStackIndex][1]; $stack[$currentStackIndex][2]=1; array_push($stack, array($stack[$currentStackIndex][0][$nextObjectIndex], sizeof($stack[$currentStackIndex][0][$nextObjectIndex]), 0, array_merge($stack[$currentStackIndex][3], array($nextObjectIndex))) ); continue;}; if( !$stack[$currentStackIndex][2] ){ $output[]=array($stack[$currentStackIndex][0], $stack[$currentStackIndex][3]); }; array_pop($stack); } return $output; /* keep this comment to reuse freely: http://www.fullposter.com/?1 */}Remove colors
function scanAssociativeAll($node){ if(!$node || !is_array($node)){return null;}; $output=array(); $stack=array( array($node, 0, 0, 0, array(), array(), array()) ); while(sizeof($stack)){ $currentStackIndex=sizeof($stack)-1; if( !$stack[$currentStackIndex][2] && is_array($stack[$currentStackIndex][0]) ){ $stack[$currentStackIndex][4]=array_keys($stack[$currentStackIndex][0]); $stack[$currentStackIndex][1]=sizeof($stack[$currentStackIndex][4]);/*decreasing length*/ $stack[$currentStackIndex][2]=sizeof($stack[$currentStackIndex][4]);/*fixed length*/ }; if(is_array( $stack[$currentStackIndex][0] ) && $stack[$currentStackIndex][1]){ if(!$stack[$currentStackIndex][3]){ $output[]=array($stack[$currentStackIndex][0], $stack[$currentStackIndex][5], $stack[$currentStackIndex][6]); }; $nextObjectIndex=( $stack[$currentStackIndex][2] - $stack[$currentStackIndex][1] ); $nextObjectAssociativeIndex=$stack[$currentStackIndex][4][$nextObjectIndex]; --$stack[$currentStackIndex][1]; $stack[$currentStackIndex][3]=1; array_push($stack, array($stack[$currentStackIndex][0][$nextObjectAssociativeIndex], 0, 0, 0, array(), array_merge($stack[$currentStackIndex][5], array($nextObjectAssociativeIndex)), array_merge($stack[$currentStackIndex][6], array($nextObjectIndex)) ) ); continue;}; if( !$stack[$currentStackIndex][3] ){ $output[]=array($stack[$currentStackIndex][0], $stack[$currentStackIndex][5], $stack[$currentStackIndex][6]); }; array_pop($stack); } return $output; /* keep this comment to reuse freely: http://www.fullposter.com/?1 */}Remove colors