ballhogjoni Posted July 23, 2013 Share Posted July 23, 2013 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 protected] 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 protected]" ); } 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 More sharing options...
requinix Posted July 23, 2013 Share Posted July 23, 2013 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. Link to comment https://forums.phpfreaks.com/topic/280408-is-this-an-encoding-issue/#findComment-1441732 Share on other sites More sharing options...
ballhogjoni Posted July 23, 2013 Author Share Posted July 23, 2013 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) Link to comment https://forums.phpfreaks.com/topic/280408-is-this-an-encoding-issue/#findComment-1441736 Share on other sites More sharing options...
requinix Posted July 23, 2013 Share Posted July 23, 2013 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. Link to comment https://forums.phpfreaks.com/topic/280408-is-this-an-encoding-issue/#findComment-1441753 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.