msimonds Posted April 24, 2008 Share Posted April 24, 2008 I am having an issue when I am trying to parse a .csv file and process it via SOAP to Salesforce.com using their API This is the first time this has happened and I need some guidance on what I can do to correct this I am reading the file, each record is an array: [DIST_NAME] => company [PARENT_BRANCH] => H387 [PROJECT_NAME] => Bussplex [END_PRODUCT] => Vehicle instrumentation [CUSTOMERNAME] => Customer [RECORD_CREATION_DATE] => 4/22/2008 [bOARD_NAME] => Main board [PROTOTYPE_DATE] => 3/7/2008 [PRODUCTION_DATE] => 6/6/2008 [bOARDSPERYEAR] => 500 [bOARD_DESIGN_PHASE] => Prototype [bOARD_FUNCTION] => CPU [REG_ID] => 999999999 [REG_NO] => [sTATUS] => Pending [PENDING_DATE] => 3/28/2008 8:56 [WIN_DATE] => [REG_PART_FAMILY] => 13442 [REG_PART_SUPPLIER_PART_NO] => 13442EASA+ [REG_PART_PRICE] => 2.04 [REG_PART_QTY_PER_BOM] => 9 [AM_NAME] => João Carlos Boaventura [FAE_NAME] => João Carlos Boaventura [CUSTOMERENGINEER] => João Carlos Boaventura [OFFICE_PHONE] => 555-1212 [email] => [email protected] [EXT_COMMENTS] => [APPR_REJ_REASON] => [RENEW_DATE] => Every file processed fine until we started receiving text with foreign characters: João I know that I could just use strtr to correct each value of the array, one by one, What I am looking to do is clean the whole entire record/array, so if this comes in from the .csv file: [AM_NAME] => João Carlos Boaventura [FAE_NAME] => João Carlos Boaventura [CUSTOMERENGINEER] => João Carlos Boaventura I can replace it with [AM_NAME] => Joao Carlos Boaventura [FAE_NAME] => Joao Carlos Boaventura [CUSTOMERENGINEER] => Joao Carlos Boaventura I tried this array_map('translate', $data); function translate($string) { $search = 'ãäåö'; $replace = 'aaao'; $string = strtr($string, $search, $replace); return $string; } but of coarse it is not working Does anyone have some function or some idea of what I need to do Hope this makes sense ~Mike Link to comment https://forums.phpfreaks.com/topic/102774-invalid-byte-2-of-3-byte-utf-8-sequence/ Share on other sites More sharing options...
Spaceman-Spiff Posted April 24, 2008 Share Posted April 24, 2008 What you need to use is not strstr(), but str_replace(); Also, $search and $replace have to be in array format. Link to comment https://forums.phpfreaks.com/topic/102774-invalid-byte-2-of-3-byte-utf-8-sequence/#findComment-526498 Share on other sites More sharing options...
effigy Posted April 24, 2008 Share Posted April 24, 2008 It appears that the data is not in UTF-8 and you are treating it that way. Where is this being done? Link to comment https://forums.phpfreaks.com/topic/102774-invalid-byte-2-of-3-byte-utf-8-sequence/#findComment-526517 Share on other sites More sharing options...
msimonds Posted April 25, 2008 Author Share Posted April 25, 2008 What you need to use is not strstr(), but str_replace(); Also, $search and $replace have to be in array format. Could you give me an example of this @effigy, sorry I am not up to speed on what is and what is not utf8, I am just posting the error that I am receiving from Salesforce's API and if I correct this one record by replacing "ã" with "a" and process the record again, it inserts perfectly. So it has to be that text that is causing the problem Thanks, ~Mike Link to comment https://forums.phpfreaks.com/topic/102774-invalid-byte-2-of-3-byte-utf-8-sequence/#findComment-526979 Share on other sites More sharing options...
effigy Posted April 25, 2008 Share Posted April 25, 2008 Try passing the data through utf8_encode. This should turn "ã" into "ã", which is valid UTF-8. Link to comment https://forums.phpfreaks.com/topic/102774-invalid-byte-2-of-3-byte-utf-8-sequence/#findComment-527091 Share on other sites More sharing options...
msimonds Posted April 25, 2008 Author Share Posted April 25, 2008 okay thank you kind sir, i will check with them Link to comment https://forums.phpfreaks.com/topic/102774-invalid-byte-2-of-3-byte-utf-8-sequence/#findComment-527099 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.