brosjr Posted January 4, 2011 Share Posted January 4, 2011 Hi all, I have this structure of two functions: function get_string_between($string, $start, $end){ $string = " ".$string; $ini = strpos($string,$start); if ($ini == 0) return ""; $ini += strlen($start); $len = strpos($string,$end,$ini) - $ini; return substr($string,$ini,$len); } function normaliza($text){ function entre($string, $start, $end){ $string = " ".$string; $ini = strpos($string,$start); if ($ini == 0) return ""; $ini += strlen($start); $len = strpos($string,$end,$ini) - $ini; return substr($string,$ini,$len); } foreach (count_chars($text, 1) as $i => $val) { if(chr($i)=='<'){ $totaltag = $val; } } for($u=0; $u <= $totaltag; $u++){ $parsed = entre($text, "<", ">"); $text = str_replace('<'.$parsed.'>',"",$text); } return $text; } The I passed a text named $data throught both functions and I got the correct return: $status = get_string_between($data, 'Inativo', 'CNPJ'); $status = normaliza($status); echo $status.' '; Just after, I passed the same folowing text throught the same both functions: $cnpj = get_string_between($data, 'CNPJ', 'Grau'); $cnpj = normaliza($status); echo $cnpj.' '; And I got this error: Cannot redeclare entre() (previously declared in C:\Users\entidade.php:47) in C:\Users\entidade.php on line 47 Why? I thougth this kind strange because it didin't gave the same error for the function get_string_between. Thanks danilo jr. Quote Link to comment https://forums.phpfreaks.com/topic/223369-cannot-redeclare-function-previously-declared-in/ Share on other sites More sharing options...
denno020 Posted January 4, 2011 Share Posted January 4, 2011 You've got a funcion definition inside another function. Fair sure you can't do this. You've got function entre() defined inside function normaliza(). Define it somewhere else (outside of all other functions) and just make a call inside normalia(). Quote Link to comment https://forums.phpfreaks.com/topic/223369-cannot-redeclare-function-previously-declared-in/#findComment-1154647 Share on other sites More sharing options...
brosjr Posted January 4, 2011 Author Share Posted January 4, 2011 Nice, thanks denno020 Quote Link to comment https://forums.phpfreaks.com/topic/223369-cannot-redeclare-function-previously-declared-in/#findComment-1154649 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.