This are my php functions:
function test($a,$b,$c) {
sanitize($a,$b,$c);
echo "$a $b $c";
}
function test2($m,$n) {
sanitize($m,$n);
echo "$m $n";
}
function sanitize() {
// escape strings with stripslashes (and other filters later)
}
test2("he'llo", "wo'rld");
test("he'llo", "wo'rld","hap'y");
Is it possible to keep test and test2 function ?
I just want to avoid having 3 lines :
$a=sanitize($a);
$b=sanitize($b);
$c=sanitize($c);
and have just:
sanitize($a, $b, $c);
Answer
Php 5.6+
function sanitize( &...$args){
foreach($args as &$arg){
//your sanitising code here, eg:
$arg = strtolower($arg);
}
}
No comments:
Post a Comment