note 99921 deleted from function.call-user-func-array by cmb

From: Date: Sun, 30 Aug 2015 18:02:27 +0000
Subject: note 99921 deleted from function.call-user-func-array by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-203511@lists.php.net to get a copy of this message
Note Submitter: hinom06 [at] hotmail.co.jp ---- <?php /* Usage sample to apply any filter in a string. */ class Strings { function Foo( $v, $allow = '' ) { return strip_tags( $v, $allow ); } // add an element at the beginning of an array // thanks for Vidal Rodríguez // http://www.php.net/manual/en/function.array-push.php#98299 function ArrayRpush( $arr, $item ) { return array_pad( $arr, -( count( $arr ) + 1 ), $item ); } } Class Functions { function Call( $f ) { return call_user_func_array( $f[0], $f[1] ); /* usage sample: // // calling function Functions::Call( 'strip_tags', array( '<br>foo<br>bar</b>', '<br><b>' ) ); // calling object Functions::Call( array( 'Strings', 'StripTags' ), array( '<br>foo<br>bar</b>', '<br><b>' ) ); */ } } $form = array( 'field' => array( 'value' => '<b>foo bar</b><br><script>alert("1");</script>', 'pre-filter' => array( array( 'Strings', 'Foo' ) , array( '<b><br>' ) ), ), ); $v = $form['field']; $f = $v['pre-filter']; $f[1] = isset( $v['pre-filter'][1] ) ? Strings::ArrayRpush( $f[1], $v['value'] ) : $f[1] = array( $v['value'] ); echo Functions::Call( $f ); ?>

« previous php.notes (#203511) next »