scott.stephan Posted July 16, 2009 Share Posted July 16, 2009 Any idea why this isn't working? replace=array(","); $sku_init=$row_itm[itm_sku]; $sku=str_replace($replace," ",$sku_init); I've also tried it $sku_init=$row_itm[itm_sku]; $sku=str_replace(","," ",$sku_init); and $sku=str_replace(","," ",$row_itm[itm_sku]); Nothing works. I must be missing the point somehow. Quote Link to comment https://forums.phpfreaks.com/topic/166250-solved-str_replace-problem/ Share on other sites More sharing options...
p2grace Posted July 16, 2009 Share Posted July 16, 2009 You need quotes around the array key. replace=array(","); $sku_init=$row_itm['itm_sku']; $sku=str_replace($replace," ",$sku_init); Quote Link to comment https://forums.phpfreaks.com/topic/166250-solved-str_replace-problem/#findComment-876709 Share on other sites More sharing options...
scott.stephan Posted July 16, 2009 Author Share Posted July 16, 2009 You need quotes around the array key. replace=array(","); $sku_init=$row_itm['itm_sku']; $sku=str_replace($replace," ",$sku_init); This still doesn't work. $sku still has commas in it. Here's the problem- One of my SKUs is "Steve's Shipper CD,WS,SL". Most of the SKUs are just "Steve's Hat" and that's fine. But I output to a CSV, so I get "Steve's Shipper, CD, WS, SL" and what I need is "Steve's Shipper CD WS SL" to aboid borking the CSV forever. This code above runs, but it doesn't change anything. The SKU still has ","s Quote Link to comment https://forums.phpfreaks.com/topic/166250-solved-str_replace-problem/#findComment-876731 Share on other sites More sharing options...
p2grace Posted July 16, 2009 Share Posted July 16, 2009 Can you echo out the original $sku_init, and then the $sku results and post them. Your code should work. Quote Link to comment https://forums.phpfreaks.com/topic/166250-solved-str_replace-problem/#findComment-876738 Share on other sites More sharing options...
Daniel0 Posted July 16, 2009 Share Posted July 16, 2009 What are you actually trying to do? As far as I know, the proper way to store values that contain the delimiter in a CSV file is to put the value in quotes. Something like: "Foo, bar, baz",test,hello Quote Link to comment https://forums.phpfreaks.com/topic/166250-solved-str_replace-problem/#findComment-876740 Share on other sites More sharing options...
scott.stephan Posted July 16, 2009 Author Share Posted July 16, 2009 Stupid- I meant to strip the commas out of another variable. Ugh. Works now. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/166250-solved-str_replace-problem/#findComment-876742 Share on other sites More sharing options...
scott.stephan Posted July 16, 2009 Author Share Posted July 16, 2009 SKU BEFORE STR REPLACE Three Seas Ship-CR,WC,DC SKU AFTER STR REPLACE Three Seas Ship-CR WC DC There we go. With code: $replace=array(","); $desc_init=$row_itm[itm_desc]; echo "SKU BEFORE STR REPLACE $desc_init <br/>"; $desc=str_replace($replace," ",$desc_init); //A few SKUs have commas in them. They drive the CSV bonkers. We pull them here. echo "SKU AFTER STR REPLACE $desc <br/>"; echo "PRE EXPLODE NOTES ARE: $notes <br/>"; Quote Link to comment https://forums.phpfreaks.com/topic/166250-solved-str_replace-problem/#findComment-876744 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.