<?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;
}
?>
str_filter() - array_filter() for strings - adapted
I've added a size variable setting the size of the blocks passed to the function.
An account is required to post comments and adaptations
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
loading
