loading

str_filter() - array_filter() for strings - adapted

I've added a size variable setting the size of the blocks passed to the function. <?php
 
function str_filter($s,$func$size=1){
  
$r '';
  for (
$i 0$i < (strlen($s)); $i=$i+$size){
   
$l substr($s,$i,$size);
   if (
call_user_func($func,$l)) $r .= $l;
  }
  return 
$r;
 }
?>
(1) | by Jove on November 9th, 2007 | adapts str_filter() - array_filter() for strings by defproc

An account is required to post comments and adaptations

tf2.flyingllamaandpandasquad.net

COMMENTS AND ADAPTATIONS

On top of Jove's $size option I've added a switch to reverse the role of the callback: with $negated as true, characters (or chunks) that have the callback return false are kept and true discarded.

(1) | an adaptation by defproc on November 16th, 2007 | read entry | 0 comments | 0 adaptations
RIP The Internet 1969-2012 | Powered by: Apache / PHP / MySQL | Made in Ninjapad NX | © defproc.co.uk, 2007_