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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.