[eluser]xwero[/eluser]
[quote author="Pygon" date="1203545129"]You might use strstr or stristr instead, since strncasecmp is only going to compare the first X characters of the string.[/quote]
You are right strncasecmp only matches the first characters. it the same as doing
Code:
array_key_matches_regex('/^update_',$_POST);
That's what i meant saying the array_key_matches_string function lacks flexibility.
Because i know the first part strncasecmp does the trick but sometimes i only need the appended data so the strstr suggestion is a nice catch. The function could be written as follows
Code:
function array_key_matches_string($string,$array,$cut=FALSE)
{
$postkeys = array_keys($array);
foreach($postkeys as $key)
{
if(strncasecmp($string,$key,strlen($string)) == 0)
{
return (!$cut)$key:substr($key,strlen($string)+1);
}
}
return false;
}
I ended up with substr because the code with strstr would be
Code:
str_replace($string,'',strstr($key,$string))
Because it returns the needle too.