str_replace not working correctly

Hi All,

first post!, Im having a problem with str_replace inside a while loop. I have an array var named $csv_header_2.

the array is look like this see below



$csv_header_2 = ("Postcard"=>"Postcard","Sticker"=>Sticker)


and so on. The loop below performs a db functions and retrieve values for each postcard, sticker etc. so if done right the array should look like this



$csv_header_2 = ("Postcard"=>1027,"Sticker"=>300)


but i get



$csv_header_2 = ("Postcard"=>"Postcard","Sticker"=>50)




while(doing something)
{
    while ($t_row = mysql_fetch_assoc($type_result)) 
    {
       $search = $t_row['product_type_name'];
       $csv_header_2 =    str_replace($search,$t_row['total_points'],$csv_header_2);
     }
     
    
}	


i cant figure this out and why it is not working, any help would be appreciated

D

Hi guido2004,

Thank you for ur replies, i managed to solve the problem in the end, using preg_match. once again thank you for ur replies :smiley:

Davinder

Please don’t forget this part, it’s fundamental :slight_smile:

do an echo of $search and see if it ever has the value “Postcard”

Hi, thanks for the reply, i have done an echo, and the values are all correct!
and i have also tried preg_replace but no luck there either!

Please do a print_r of $csv_header_2 before the loop, one after, and an echo of $search in the loop, and post the results here.


//before str_replace
Array
(		
    [Certificate] => Certificate		
    [Postcard] => Postcard		
    [Sticker] => Sticker		
)

//after		
Array		
(		
    [Certificate] => Certificate		
    [Postcard] => Postcard		
    [Sticker] => 500
)