Discussion:
Fatal error: Cannot redeclare function()
(too old to reply)
a***@coopedupcomputers.com
2008-10-03 18:01:17 UTC
Permalink
When I execute this code:

<?php 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);
}

$fullstring = $row_getRecords['agent'];
$parsed = get_string_between($fullstring, ".", "@");

echo $parsed; ?>

I get this error:

Fatal error: Cannot redeclare get_string_between() (previously
declared in /home....

I have this function wrapped in a do while loop which I think is
causing my problem. I get one result, then the error message. I have
one call to another page, but set it up as include_once. Anyone know
what may be causing it? The $agent variable is an email address. I'm
trying to grab the last name of the agent with this function. If
anyone has another method to do this, I'd be willing to try!

Azo
SLerman
2008-10-03 19:44:14 UTC
Permalink
Post by a***@coopedupcomputers.com
<?php 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);
}
$fullstring = $row_getRecords['agent'];
echo $parsed; ?>
Fatal error: Cannot redeclare get_string_between() (previously
declared in /home....
I have this function wrapped in a do while loop which I think is
causing my problem. I get one result, then the error message. I have
one call to another page, but set it up as include_once. Anyone know
what may be causing it? The $agent variable is an email address. I'm
trying to grab the last name of the agent with this function. If
anyone has another method to do this, I'd be willing to try!
Azo
Don't define the function inside a loop. Define it before the loop.
Continue reading on narkive:
Loading...