kkroo Posted March 22, 2006 Share Posted March 22, 2006 i am making a script that will get the var names of arrays through file(), this is what i currently have:[code]// This function was found on http:php.net/preg_matchfunction array_preg_match($strRegEx = "", $arrHaystack = NULL, $boolNewArray = 0, $boolMatchesOnly = 0) { if (strlen($strRegEx) < 1) { return "ERR: \$strRegEx argument is missing."; } elseif ((!is_array($arrHaystack)) || (!count($arrHaystack) > 0)) { return "ERR: \$arrHaystack is empty, or not an array."; } else { unset($arrTmp); // search through $arrHaystack, and build new array foreach($arrHaystack as $key => $value) { if ($boolMatchesOnly) { if (preg_match_all($strRegEx, $value, $tmpRes)) { $arrTmp[] = $tmpRes; } } else { if (preg_match($strRegEx, $value, $tmpRes)) { if ($boolNewArray) { $arrTmp[] = $value; } else { $arrTmp[$key] = $value; } } } } return $arrTmp; }}// My function function get_array_names ($file) { $file = file($file); $names = array_preg_match('(\$lang\[.*\])', $file); return array_values($names);} [/code]I want it to return:Array( [0] => $lang['Test'] [1] => $lang['Test1'] [2] => $lang['Test2'])BUT it returns Array( [0] => $lang['Test'] = array( [1] => $lang['Test1'] = array( [2] => $lang['Test2'] = array()can anyone help me out? Quote Link to comment https://forums.phpfreaks.com/topic/5529-preg_match-for-arrrays/ Share on other sites More sharing options...
kkroo Posted March 23, 2006 Author Share Posted March 23, 2006 bump! Quote Link to comment https://forums.phpfreaks.com/topic/5529-preg_match-for-arrrays/#findComment-19926 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.