Page 1 of 1

Don't know why! same code runs a time and don't another time

Posted: Fri Jan 17, 2003 5:40 am
by schmid
Hi all,
in the same script code sometimes run and sometimes not *grumble
Take a look at this:

$count = count($data);
//this way count is ok
//echo $count;

// this way I'm not able to replace it with $count
$out = ereg_replace('##ANZAHL##', $count, $parts[0]);

// template is ok this way the template runs and replaces with test
//$out = ereg_replace('##ANZAHL##', "test", $parts[0]);

echo $out;


// this time a few lines above it runs fine
$i = 0;
while(each($data)):
list($id,$zeit,$name,$mail,$web,$text,$comment) = $data[$i];
$out1 = ereg_replace('##NUMMER##', $id, $parts[1]);
$out1 = ereg_replace('##ZEIT##', $zeit, $out1);
$out1 = ereg_replace('##NAME##', $name, $out1);
to be continued......

can anybody tell me why?
I did everything, I also deleted file from server and wrote it again.
thx for help

schmid

Got it ;-)

Posted: Fri Jan 17, 2003 6:29 am
by schmid
dont give ereg_replace an integer cause it will see it as ordinal of a string.
you have to deklare this integer as string like:
$variable = '3';
or
variable = (string)count($array);
explizit casting ;-)

cya
schmid