![]()
Snippets of A |
|
|
What are snippets? |
|
function findFile($node, $value, $limit=0, $separator="\\"){ //validate: if(!is_dir($node) || !isset($value) || $value===""){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) ); //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; if(is_dir($path)){ $directories[]=$path; $stack[]=array( $path, substr_count($path, $newSeparator) );} else if($it === $value){return $path;}; }; } return false; /* keep this comment to reuse freely: http://www.fullposter.com/?1 */}Remove colors
null in case of wrong inputs, boolean false if no file is found or the string path to the found file, inclusive of the file name.
function findFilei($node, $value, $limit=0, $separator="\\"){ //validate: if(!is_dir($node) || !isset($value) || $value===""){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) ); $value=strtolower($value); //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; if(is_dir($path)){ $directories[]=$path; $stack[]=array( $path, substr_count($path, $newSeparator) );} else if(strtolower($it) === $value){return $path;}; }; } return false; /* keep this comment to reuse freely: http://www.fullposter.com/?1 */}Remove colors
function findFiles($node, $value, $limit=0, $separator="\\"){ //validate: if(!is_dir($node) || !isset($value) || $value===""){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; $output=array(); $stack=array( array($node, $slashes) ); //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; if(is_dir($path)){ $directories[]=$path; $stack[]=array( $path, substr_count($path, $newSeparator) );} else if($it === $value){$output[]=$path;}; }; } return $output; /* keep this comment to reuse freely: http://www.fullposter.com/?1 */}Remove colors
null in case of wrong inputs, an empty array if no file is found or an array whose each item is a string path to the found file(s), inclusive of the file name(s).
function findFilesi($node, $value, $limit=0, $separator="\\"){ //validate: if(!is_dir($node) || !isset($value) || $value===""){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; $output=array(); $stack=array( array($node, $slashes) ); $value=strtolower($value); //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; if(is_dir($path)){ $directories[]=$path; $stack[]=array( $path, substr_count($path, $newSeparator) );} else if(strtolower($it) === $value){$output[]=$path;}; }; } return $output; /* keep this comment to reuse freely: http://www.fullposter.com/?1 */}Remove colors
function findFiless($node, $value, $limit=0, $separator="\\"){ //validate: if(!is_dir($node) || !isset($value) || $value===""){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; $output=array(); $stack=array( array($node, $slashes) ); $value=strtolower($value); //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; if(is_dir($path)){ $directories[]=$path; $stack[]=array( $path, substr_count($path, $newSeparator) );} else if(strpos(strtolower($it), $value) !== false){$output[]=$path;}; }; } return $output; /* keep this comment to reuse freely: http://www.fullposter.com/?1 */}Remove colors
null in case of wrong inputs, an empty array if no file is found or an array whose each item is a string path to the found file(s), inclusive of the file name(s).
function findFilesr($node, $regexp, $limit=0, $separator="\\"){ //validate: if(!is_dir($node) || !is_string($regexp)){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; $output=array(); $stack=array( array($node, $slashes) ); //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; if(is_dir($path)){ $directories[]=$path; $stack[]=array( $path, substr_count($path, $newSeparator) );} else if(preg_match($regexp,$it)){$output[]=$path;}; }; } return $output; /* keep this comment to reuse freely: http://www.fullposter.com/?1 */}Remove colors
i flag to make it case insensitive if you prefer so.
null in case of wrong inputs, an empty array if no file is found or an array whose each item is a string path to the found file(s), inclusive of the file name(s).
function findFiler($node, $regexp, $limit=0, $separator="\\"){ //validate: if(!is_dir($node) || !is_string($regexp)){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) ); //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; if(is_dir($path)){ $directories[]=$path; $stack[]=array( $path, substr_count($path, $newSeparator) );} else if(preg_match($regexp,$it)){return $path;}; }; } return false; /* keep this comment to reuse freely: http://www.fullposter.com/?1 */}Remove colors
i flag to make it case insensitive if you prefer so.
null in case of wrong inputs, boolean false if no file is found or the string path to the found file, inclusive of the file name.
function find($node, $value){ if(!$node || !is_array($node) || (!isset($value) && $value!==null)){return null;}; $stack=array( array($node, sizeof($node), 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]; array_push($stack, array($stack[$currentStackIndex][0][$nextObjectIndex], sizeof($stack[$currentStackIndex][0][$nextObjectIndex]), array_merge($stack[$currentStackIndex][2], array($nextObjectIndex))) ); continue;}; if( $stack[$currentStackIndex][0] === $value ){ return array($stack[$currentStackIndex][0], $stack[$currentStackIndex][2]); }; array_pop($stack); } return false; /* keep this comment to reuse freely: http://www.fullposter.com/?1 */}Remove colors
null in case of wrong inputs, boolean false if no such value is found or an array of two items. The first is the item found at the end of each branch, and the second item is an array again, whose each entry is a number: that is the map of all the traversed indexes to get at the reported item.
function findAll($node, $value){ if(!$node || !is_array($node) || (!isset($value) && $value!==null)){return null;}; $output=array(); $stack=array( array($node, sizeof($node), 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]; array_push($stack, array($stack[$currentStackIndex][0][$nextObjectIndex], sizeof($stack[$currentStackIndex][0][$nextObjectIndex]), array_merge($stack[$currentStackIndex][2], array($nextObjectIndex))) ); continue;}; if( $stack[$currentStackIndex][0] === $value ){ $output[]=array($stack[$currentStackIndex][0], $stack[$currentStackIndex][2]); }; array_pop($stack); } return $output; /* keep this comment to reuse freely: http://www.fullposter.com/?1 */}Remove colors
null in case of wrong inputs, an empty array if no such value is found or an array of two items. The first is the item found at the end of each branch, and the second item is an array again, whose each entry is a number: that is the map of all the traversed indexes to get at the reported item.
function associativeFind($node, $value){ if(!$node || !is_array($node) || (!isset($value) && $value!==null)){return null;}; $stack=array( array($node, 0, 0, array(), array(), array()) ); while(sizeof($stack)){ $currentStackIndex=sizeof($stack)-1; if( !$stack[$currentStackIndex][2] && is_array($stack[$currentStackIndex][0]) ){ $stack[$currentStackIndex][3]=array_keys($stack[$currentStackIndex][0]); $stack[$currentStackIndex][1]=sizeof($stack[$currentStackIndex][3]);/*decreasing length*/ $stack[$currentStackIndex][2]=sizeof($stack[$currentStackIndex][3]);/*fixed length*/ }; if(is_array( $stack[$currentStackIndex][0] ) && $stack[$currentStackIndex][1]){ $nextObjectIndex=( $stack[$currentStackIndex][2] - $stack[$currentStackIndex][1] ); $nextObjectAssociativeIndex=$stack[$currentStackIndex][3][$nextObjectIndex]; --$stack[$currentStackIndex][1]; array_push($stack, array($stack[$currentStackIndex][0][$nextObjectAssociativeIndex], 0, 0, array(), array_merge($stack[$currentStackIndex][4], array($nextObjectAssociativeIndex)), array_merge($stack[$currentStackIndex][5], array($nextObjectIndex)) ) ); continue;}; if( $stack[$currentStackIndex][0] === $value ){ return array($stack[$currentStackIndex][0], $stack[$currentStackIndex][4], $stack[$currentStackIndex][5]); }; array_pop($stack); } return false; /* keep this comment to reuse freely: http://www.fullposter.com/?1 */}Remove colors
null in case of wrong inputs, boolean false if no such value is found or an array of two items. The first is the item found at the end of each branch, and the second item is an array again, whose each entry is a number: that is the map of all the traversed indexes to get at the reported item.
function associativeFindAll($node, $value){ if(!$node || !is_array($node) || (!isset($value) && $value!==null)){return null;}; $output=array(); $stack=array( array($node, 0, 0, array(), array(), array()) ); while(sizeof($stack)){ $currentStackIndex=sizeof($stack)-1; if( !$stack[$currentStackIndex][2] && is_array($stack[$currentStackIndex][0]) ){ $stack[$currentStackIndex][3]=array_keys($stack[$currentStackIndex][0]); $stack[$currentStackIndex][1]=sizeof($stack[$currentStackIndex][3]);/*decreasing length*/ $stack[$currentStackIndex][2]=sizeof($stack[$currentStackIndex][3]);/*fixed length*/ }; if(is_array( $stack[$currentStackIndex][0] ) && $stack[$currentStackIndex][1]){ $nextObjectIndex=( $stack[$currentStackIndex][2] - $stack[$currentStackIndex][1] ); $nextObjectAssociativeIndex=$stack[$currentStackIndex][3][$nextObjectIndex]; --$stack[$currentStackIndex][1]; array_push($stack, array($stack[$currentStackIndex][0][$nextObjectAssociativeIndex], 0, 0, array(), array_merge($stack[$currentStackIndex][4], array($nextObjectAssociativeIndex)), array_merge($stack[$currentStackIndex][5], array($nextObjectIndex)) ) ); continue;}; if( $stack[$currentStackIndex][0] === $value ){ $output[]=array($stack[$currentStackIndex][0], $stack[$currentStackIndex][4], $stack[$currentStackIndex][5]); }; array_pop($stack); } return $output; /* keep this comment to reuse freely: http://www.fullposter.com/?1 */}Remove colors
null in case of wrong inputs, an empty array if no such value is found or an array of two items. The first is the item found at the end of each branch, and the second item is an array again, whose each entry is a number: that is the map of all the traversed indexes to get at the reported item.