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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
schmid
Forum Newbie
Posts: 3
Joined: Thu Jan 16, 2003 2:25 pm
Contact:

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

Post 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
schmid
Forum Newbie
Posts: 3
Joined: Thu Jan 16, 2003 2:25 pm
Contact:

Got it ;-)

Post 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
Post Reply