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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.