BigToach.com

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
?>

Added on Oct 23rd at 9 am by Scott - 4 Comments


4 Responses to find_functions

helena (sander[at]unity-x[dot]nl) commented on Feb 14th at 6 am
doet ie het!!!!
helena (sander[at]unity-x[dot]nl) commented on Feb 14th at 6 am
doet ie het!!!!
helena (sander[at]unity-x[dot]nl) commented on Feb 14th at 6 am
doet ie het!!!!
Scott commented on Feb 14th at 3 pm
I agree

Name:

Site or Mail:

Comment:

To try to reduce the ammount of spam, please enter the word GOOSE in the following form

Security Code: