Jump to content

[SOLVED] str_replace problem.


scott.stephan

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/166250-solved-str_replace-problem/
Share on other sites

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

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/>";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.