Jump to content

Is this an encoding issue?


Go to solution Solved by requinix,

Recommended Posts

So I am receiving order information from Amazon.com and writing it to a file to send to my supplier to fulfill the order but some orders have these ^ and @ characters in the address. I've checked the data in Amazon and the order doesn't include the ^ and @ characters. What could my code be doing to add these characters?

 

This is a semicolon delimited file row:

002-8228257;10;^@william lastname^@;^@123 TEST RD^@;^@THE CITY^@;OHIO;12345;8017055555;Y;email@email.com

 

I create a $data array and loop through the orders adding each row into the array. I then use fputcsv to write the rows to the file

foreach ($orders as $order) {
  $data[] = array(
            $order["amazon_order_id"], "10", $order[0]["ship_to_name"],
            $order[0]["ship_to_addr_one"],
            $order[0]["city"], $state, $order[0]["zip"],
            str_replace('-', '', $order[0]["phone"]),
            "Y", "email@email.com"
  );
}
foreach ($data as $row)
      fputcsv($handle, $row, ";", chr(0));

 

Link to comment
https://forums.phpfreaks.com/topic/280408-is-this-an-encoding-issue/
Share on other sites

  • Solution

Use a different editor to look at the file. It's using a typical representation of control characters by showing them as "^" + chr(64 + code), like how you might see ^C if you hit Ctrl+C with a command-line application.

Use a different editor to look at the file. It's using a typical representation of control characters by showing them as "^" + chr(64 + code), like how you might see ^C if you hit Ctrl+C with a command-line application.

 

Awesome thanks for that info. This is how I am fixing the issue. Let me know if this is the best way to remove control characters:

str_replace(range("\x00","\x1F"), "", $str)

It's not.

 

fputcsv($handle, $row, ";", chr(0));
You specifically say in your code to use \0 as the quoting character. If you don't want that then don't do it and pick something else. Or let PHP go with the perfectly reasonable default value of an actual quote character.
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.