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@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)); Quote Link to comment Share on other sites More sharing options...
Solution requinix Posted July 23, 2013 Solution 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. Quote Link to comment 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) Quote Link to comment 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. Quote Link to comment 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.