dsdsdsdsd Posted February 2, 2012 Share Posted February 2, 2012 hello; I have: mysql: utf8_general_ci index.php: header( ... UTF- index.php: <meta ... content-type ... UTF-8> index.php, mysql query procedure: ... mysql_set_charset( utf8 , .. ) ... So, if I put a special character in my db, it WILL display correctly in index.php But, if I put the same character in a php variable, it is BAD ... diamond-shape with question mark inside Since my special characters work from the db, I would like to also use them in html (index.php ). am I missing anything? thanks for your time .. Shannon Quote Link to comment https://forums.phpfreaks.com/topic/256267-special-character-from-db-good-from-php-bad/ Share on other sites More sharing options...
MadTechie Posted February 2, 2012 Share Posted February 2, 2012 IT should work from the PHP variable as well, I am going to assume you believe it doesn't as you have typed it into the code and fails, this is because the PHP file itself is not UTF-8, for example if you read the text from the database then it will go into a PHP variable, and then you should be able to echo it out (assuming you have a UTF-8 char-set). I don't think your missing anything but then again I'm not sure of the question/problem! :-\ Quote Link to comment https://forums.phpfreaks.com/topic/256267-special-character-from-db-good-from-php-bad/#findComment-1313772 Share on other sites More sharing options...
dsdsdsdsd Posted February 2, 2012 Author Share Posted February 2, 2012 weird weird weird .... I did not mention in the original post that there are actually 2 php pages, one included by the other. I determined that the variables from the included file were the problem (if I moved them to the main.php, no problems). I use dreamweaver as my text editor AND APPARENTLY dreamweaver saves the files with an encoding, and indeed the included.php was saved with Western encoding. in dreamweaver: CTRL-J ... TITLE/ENCODING ... ENCODING so even though I had header( ... UTF- all over the place, the included.php did not care as it was saved in Western encoding. Quote Link to comment https://forums.phpfreaks.com/topic/256267-special-character-from-db-good-from-php-bad/#findComment-1313807 Share on other sites More sharing options...
Adam Posted February 2, 2012 Share Posted February 2, 2012 As MedTechie said: [...] this is because the PHP file itself is not UTF-8 [...] Quote Link to comment https://forums.phpfreaks.com/topic/256267-special-character-from-db-good-from-php-bad/#findComment-1313815 Share on other sites More sharing options...
dsdsdsdsd Posted February 3, 2012 Author Share Posted February 3, 2012 I am unfamiliar with the idea that a .php (which is just plain text) can have itself be 'utf8' or whatever. Where is this info stored? If I take my .php file, upload to a remote server ... where is that data from dreamweaver stored ... there's nothing visible in a text editor showing that DW injected something into it. thanks, Shannon Quote Link to comment https://forums.phpfreaks.com/topic/256267-special-character-from-db-good-from-php-bad/#findComment-1313849 Share on other sites More sharing options...
MadTechie Posted February 3, 2012 Share Posted February 3, 2012 Most editor don't display the encoding but it is their, If your editing the file in dreamweaver, then your need to tell DW that the file needs to be UTF-8 Edit->preferences->New Document->encoding (set to UTF- then create a new document and copy the contents from the old file to the new one, (if the text is look wrong your need to re-enter the text) here is an example of 2 files. http://madtechiesupport.com/phpfreaks/UTF8/ASCII.php http://madtechiesupport.com/phpfreaks/UTF8/UTF-8.php and the code http://madtechiesupport.com/phpfreaks/UTF8/code.zip Now your see that the UTF-8 file had this $array = array( 'Hello', '¡Hola', 'مرحبا', 'Γεια σας', '您好', ); While the ascii has $array = array( 'Hello', '¡Hola', '?????', 'Ge?a sa?', '??', ); If you open the ascii.php and type any special chars they won't display because the file is ascii encoded, BUT they will work in the UTF-8 file. So the question is does the text display correctly in the file (when in the editor) do you have a sample we can see ? Quote Link to comment https://forums.phpfreaks.com/topic/256267-special-character-from-db-good-from-php-bad/#findComment-1313861 Share on other sites More sharing options...
dsdsdsdsd Posted February 3, 2012 Author Share Posted February 3, 2012 I wish I was getting the same result as you ... within my texteditor (dreamweaver) characters display fine, regardless of whether I am using Western or utf8. But when I look at it in the browser, then I get the ?-marks when having used the Western. . <?php header('Content-Type:text/html; charset=UTF-8'); $gvs = "Č芚ŽžÄäÉéÖöÜüß" ; print $gvs ; ?> If I was getting the ?-marks in the texteditor environment, I would actually be relieved: wysiwyg, which is always reliable So I guess I am still confused about where the texteditor's encoding is actually stored, since it doesn't seem to be stored in the .php's visible space. -Shannon Quote Link to comment https://forums.phpfreaks.com/topic/256267-special-character-from-db-good-from-php-bad/#findComment-1313961 Share on other sites More sharing options...
Ivan Ivković Posted February 3, 2012 Share Posted February 3, 2012 Check your PHP file encoding. It should be UTF8. Quote Link to comment https://forums.phpfreaks.com/topic/256267-special-character-from-db-good-from-php-bad/#findComment-1313963 Share on other sites More sharing options...
MadTechie Posted February 3, 2012 Share Posted February 3, 2012 You say you get the ? when using Western, may i ask why your using Western instead of UTF-8 or are you getting the same for both ? Can you upload a file that doesn't work, (just a sample) posting the code won't help as much as this site will convert them. Quote Link to comment https://forums.phpfreaks.com/topic/256267-special-character-from-db-good-from-php-bad/#findComment-1314017 Share on other sites More sharing options...
dsdsdsdsd Posted February 3, 2012 Author Share Posted February 3, 2012 this is a php file ... it's only content is: <?php header('Content-Type:text/html; charset=UTF-8'); $gvs = "Č芚ŽžÄäÉéÖöÜüß" ; print $gvs ; ?> my text editor is dreamweaver. currently this file has been encoded as Western. But notice the header(... utf-8 ). low and behold the DW setting dominates even when the php file IS NOT in the text editor environment, but rather in a browser environment. Ivan, MadTechie ... I wasn't really using Western ... in fact I was unaware that DW even had this setting available at all. So my question is: where is the DW encoding setting actually being stored ... there's no visible indicators in the text editor. if I change the DW setting to 'utf8', all is well in the browser. - thanks, Shannon 17482_.php Quote Link to comment https://forums.phpfreaks.com/topic/256267-special-character-from-db-good-from-php-bad/#findComment-1314148 Share on other sites More sharing options...
MadTechie Posted February 3, 2012 Share Posted February 3, 2012 I just checked the file you uploaded and it was encoded as ASCII, this means the data is stored in a ASCII format, and your outputting as a UTF-8 format.. ASCII: http://madtechiesupport.com/phpfreaks/UTF8/test_special_chars_DW_encoding_setting.php UTF-8: http://madtechiesupport.com/phpfreaks/UTF8/test_special_chars_DW_encoding_setting_v2.php *UTF-8 without BOM: http://madtechiesupport.com/phpfreaks/UTF8/test_special_chars_DW_encoding_setting_v2.php *Recommended Note that I took off the header v2, as the BOM would mess it up, but in V3 its fine, Download the V3 and open it in DM and replace its contents with your contents and it should be fine, your need to tell DW that the file needs to be UTF-8 Edit->preferences->New Document->encoding (set to UTF- then create a new document and copy the contents from the old file to the new one, (if the text is look wrong your need to re-enter the text) 17483_.php 17484_.php Quote Link to comment https://forums.phpfreaks.com/topic/256267-special-character-from-db-good-from-php-bad/#findComment-1314160 Share on other sites More sharing options...
dsdsdsdsd Posted February 3, 2012 Author Share Posted February 3, 2012 very interesting ... this has been a learning experience for me ... I take for granted that .php files are 'text', but they are not ... rather they are rendered as text even in the text-editor-environment ... thanks. Quote Link to comment https://forums.phpfreaks.com/topic/256267-special-character-from-db-good-from-php-bad/#findComment-1314190 Share on other sites More sharing options...
MadTechie Posted February 3, 2012 Share Posted February 3, 2012 Think of it this way! BOM is a hidden text file header.. Now ignore that as i use UTF-8 without BOM Now just say 65 = A in ASCII and 0065 = A in UNICODE (UTF- So if i view A in UNICODE (its raw data is 0065) And if i view A in ASCII (its raw data is 65) BUT if I view 0065 in ASCII it would show [nul]A (00 being nul) How about other characters for example ß in UNICODE is basically ß ASCII (but looks better in UNICODE) this is because ASCII only has 255 characters, so displays the bytes as 2 character instead of 1. for more details see here or google in any case, PHP files are text but they can be encoded many different ways, the encoding is used to store and display the text, for example should it display 2 bytes as ß or ß I hope that clears thing up Quote Link to comment https://forums.phpfreaks.com/topic/256267-special-character-from-db-good-from-php-bad/#findComment-1314197 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.