Jump to content

Cannot redeclare function() previously declared in


brosjr

Recommended Posts

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.

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().

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.