0

I have a client who will be uploading text_data.php documents to a server ... the data will then be processed for mysql insert.

I do not have control on what editor the client uses, or what kind of encoding that their editor will set for the .php file when they create a new one; and I think it will be too difficult to instruct them to be sure to always ensure utf-8 when they create a new document.

I use Dreamweaver, and it sets the encoding to Western European, by default. This leads to problems when there is a special character, such as Ž within the text_data. But if I manually change the Dreamweaver setting for a particular file to utf-8, it works.

I have tried putting header('Content-Type: text/plain; charset=utf-8'); into the top of the .php file, but it does not override the Dreamweaver setting of Western European.

**EXAMPLE**
// some_text_data.php ... created by client and ftp'd to server
<?php
  $clients_data = "Šport" ;
?>
// then client goes to www.blah.com/process_the_text_data.php
//    which will read the $clients_data, and do a mysql query 
//       to insert it into a table.
//
// my_processor.php    
<?php
  $my_query = "INSERT INTO my_table (column1) 
               VALUES (" . iconv(mb_detect_encoding($clients_data, mb_detect_order(), true), 'UTF-8', $clients_data) . ") " ;
?>
dsdsdsdsd
  • 2,880
  • 6
  • 41
  • 56
  • will the script be run? or does it automatically upload the data? try either utf8_encode() which will only work on ISO-8859-1 strings or try iconv() if you know the encoding that is being used and you can use mb_detect_encoding to detect encoding. – Liam Sorsby Jan 31 '14 at 13:28
  • *"I have tried putting `header('Content-Type: text/plain; charset=utf-8');` into the top of the .php file, but it does not override the Dreamweaver setting of Western European."* — Informing the browser that something is UTF-8 does not make that something UTF-8. (And Dreamweaver is still using ISO-8859? Really? In the 21st century? 8859 has been legacy for well over a decade) – Quentin Jan 31 '14 at 13:30
  • the solution provided by the duplicate post does NOT fix all characters, for instance `č` ... ... ... nevertheless I have edited my question to show the solution posted by that duplicate. – dsdsdsdsd Jan 31 '14 at 13:50

0 Answers0