PHP Snippets
find_functions
Information
(PHP Version >= 4)Functions used in this snippet: preg_replace, preg_match_all, in_array, implode.
Description
str find_functions( str str )
Finds every function in the string str. It returns a string of the functions seperated by commas with no spaces.
Snippet
<?php
function find_functions($str)
{
$str = preg_replace('/function ([a-z0-9_]+)\s?\(/ims','',$str);
preg_match_all('/([a-z0-9_]+)\s?\(/ims',$str,$matches);
$reserved = array('if', 'foreach', 'for', 'do', 'while', 'array', 'print', 'switch', 'echo');
$ret = array();
foreach($matches[1] as $key=>$function)
{
if(!in_array($function, $reserved))
{
$ret[] = $function;
$reserved[] = $function;
}
}
return implode(',',$ret);
}
?>
Example
find_functions Can be used in the following way:
<?php
$str = '$var = str_replace("haha", "wee", "haha wee");
print_r($_SERVER);
echo substr ($_SERVER["REMOTE_ADDR"], 0, strpos($_SERVER["REMOTE_ADDR"], ".") -1);
echo pi();';
echo find_functions($str);
// returns the following
// str_replace,print_r,substr,strpos,pi
?>
4 Responses to find_functions
doet ie het!!!!
doet ie het!!!!
doet ie het!!!!
I agree