
Good people, I have a small question: suppose I have a string with native PHP or user defined functions names separated with a known separator, e.g. $myString = "strip_tags|trim|myFunction"; And I want to apply each function name to some other data e.g. $cleanData = strip_tags(trim(myFunction($dirtyData))); How would I go about it? It has been done in CodeIgniter form validation library but for the life of me I can't see how to reverse engineer it.

*call_user_func('myFunction',$dirtyData**);* * * *I have never tried nesting the above tho * *Jaribu utuambie.* * * * * _______________________________________________ *#define TRUE FALSE* //Happy debugging suckers! _______________________________________________ * * 2011/8/8 Peter Karunyu <pkarunyu@gmail.com>
Good people, I have a small question:
suppose I have a string with native PHP or user defined functions names separated with a known separator, e.g. $myString = "strip_tags|trim|myFunction";
And I want to apply each function name to some other data e.g. $cleanData = strip_tags(trim(myFunction($dirtyData)));
How would I go about it? It has been done in CodeIgniter form validation library but for the life of me I can't see how to reverse engineer it.
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke

If you want more control, you can also use eval just like JavaScript but you will have to audit the living daylights out of your code. Some love it when a client side data is passed to the eval function _______________________________________________ *#define TRUE FALSE* //Happy debugging suckers! _______________________________________________ * * 2011/8/8 James Nzomo <kazikubwa@gmail.com>
*call_user_func('myFunction',$dirtyData**);* * * *I have never tried nesting the above tho * *Jaribu utuambie.* * * * *
_______________________________________________
*#define TRUE FALSE* //Happy debugging suckers! _______________________________________________ *
*
2011/8/8 Peter Karunyu <pkarunyu@gmail.com>
Good people, I have a small question:
suppose I have a string with native PHP or user defined functions names separated with a known separator, e.g. $myString = "strip_tags|trim|myFunction";
And I want to apply each function name to some other data e.g. $cleanData = strip_tags(trim(myFunction($dirtyData)));
How would I go about it? It has been done in CodeIgniter form validation library but for the life of me I can't see how to reverse engineer it.
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke

Something like this...decided to tinker a bit since I'm on a kinda long break :) I assumed $dirtyData is a string...modify it as you see fit <?php $myString = "strip_tags|trim|myFunction"; function str2Function($str,$dirtyData) { $str = explode('|',$str); $fn = ''; for($i = count($str); $i >= 0; $i--) { if(strlen(trim($str[$i])) > 1) { $arg = ''; if($i == count($str) - 1) { $arg = '"'.$dirtyData.'"'; } else { $arg = $fn; } $fn = $str[$i].'('.$arg.')'; } } //echo $fn; return eval($fn); } $cleanData = str2Function($myString,$dirtyData); ?>

Thanks guys! I used call_user_func() together with is_callable() and it worked flawlessly! I'll be posting the result of that shortly. On Mon, Aug 8, 2011 at 8:32 PM, Haggai Nyang <haggai.nyang@gmail.com> wrote:
Something like this...decided to tinker a bit since I'm on a kinda long break :)
I assumed $dirtyData is a string...modify it as you see fit
<?php $myString = "strip_tags|trim|myFunction"; function str2Function($str,$dirtyData) { $str = explode('|',$str); $fn = ''; for($i = count($str); $i >= 0; $i--) { if(strlen(trim($str[$i])) > 1) { $arg = ''; if($i == count($str) - 1) { $arg = '"'.$dirtyData.'"'; } else { $arg = $fn; } $fn = $str[$i].'('.$arg.')'; } } //echo $fn; return eval($fn); } $cleanData = str2Function($myString,$dirtyData); ?>
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
-- Regards, Peter Karunyu ------------------- Web Performance Evangelist *Make your website and web app faster.*
participants (3)
-
Haggai Nyang
-
James Nzomo
-
Peter Karunyu