note 99921 added to function.call-user-func-array

From: Date: Wed, 15 Sep 2010 04:27:01 +0000
Subject: note 99921 added to function.call-user-func-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-172568@lists.php.net to get a copy of this message
<?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 ); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 118.17.191.44 ---- Manual Page -- http://www.php.net/manual/en/function.call-user-func-array.php Edit -- https://master.php.net/note/edit/99921 Del: integrated -- https://master.php.net/note/delete/99921/integrated Del: useless -- https://master.php.net/note/delete/99921/useless Del: bad code -- https://master.php.net/note/delete/99921/bad+code Del: spam -- https://master.php.net/note/delete/99921/spam Del: non-english -- https://master.php.net/note/delete/99921/non-english Del: in docs -- https://master.php.net/note/delete/99921/in+docs Del: other reasons-- https://master.php.net/note/delete/99921 Reject -- https://master.php.net/note/reject/99921 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#172568) next »