First, sorry my english isn't very good.
I have a problem, when I download an Excel File from a Website(direct download) it works on Windows but it isn't working on MAC.
I get the Names and Prenames etc. from a Mysql database.
The german "ä - ü - ö" are not properly converted on MAC.
How can I convert this? Do you know what I mean?
I work with Notepad++.
Programming Language is PHP
Excel version : 2010.
From what you told I suppose you have a PHP script that generates a CSV file with data from your database.
So this sounds like a typical encoding/charset problem to me. You have to define in which encoding you want to store your texts in the database. That's in the most common case UTF-8 these days. For german texts (suppose thats the language because of the umlauts) you could also use ISO-8859-15 encoding.
It's just a guess but in your case I think maybe you did not specify how the browser should interpret the received CSV file.
You normally tell the browser about it in a http header.
Content-Type: text/plain; charset="ISO-8859-15"
or whatever charset you are using (Maybe "UTF-8" instead).
Maybe the PHP header function docu helps you setting the http header.
It's also possible to define the charset in the HTML page. But I think in your case you let the PHP script sends the CSV file and not HTML. But for the record, setting the charset in HTML:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Related
folks, I need you help please.
I have a form with some inputs that expect some special chars. Thats why I want to use utf-8 encoding. It set it in HTML as a meta-tag, in PHP as a header and directly in the form with "accept-charset". Yet, I get the following:
var_dump($_POST['name']) => "dagã¶bert" (original input: "dägobert")
var_dump(mb_detect_encoding($_POST['vorname'])); => "ascii"
I have absolutely no idea left on what more to do to get this working. I appreciate any hint.
To make sure, that your web server output (from php) is interpreted as utf-8, you can set the encoding explicitly by calling:
header('Content-type: text/html; charset=utf-8');
at the beginning of your php script. It is important that this is called before any other output is done by the script, else an error occurs, that headers could not be set any more.
The <meta charset="utf-8"> tag is not sufficient. You should use the meta tag as well to provide the encoding even in the case that a user decides to store the page locally and view it later again (when noch Content-Type is provided any more, because the page doesn't come from the web server any more).
I am really really knew to php .
I have been doing asp.net etc earlier , and this php appears a whole lot different.
I am using drupal 7 , and the project has been already made.
I was told to do something very trivial but I am unable to do so. It is regarding arabic.
I declare a simple variable like $simpleText = "شهس ". Then i do drupal_set_message($simpleText).
What I then see on the web browser are ??? instead of the arabic . I have confirmed that the content type of the page is set to UTF-8. This is the meta tag of the rendered HTML on browser
Can you please help me identify how to eradicate this issue ?
Thanks.
I completed many PHP projects (including Drupal projects) and there is nothing wrong with PHP and Arabic :)
add this to your HTML and it should work just fine
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
or using PHP do this before releasing any output
header('Content-Type: text/html; charset=utf-8');
You need to set this line in connection string:
mysql_query("set character_set_server='utf8'");
mysql_query("set names 'utf8'");
You should save your file with UTF-8 encoding. If you are using Visual Studio, use "Advanced Save Options" with encoding: "Unicode (UTF-8 without signature) - Codepage 65001"
I am currently moving blog posts from wordpress to drupal. however after moving it
some of the text is not being displayed correctly.
wordpress is displaying :
When it hasn’t (html code is <h2>When it hasn’t</h2>)
Drupal is displaying :
When it hasn’t (html code is <h2>When it hasn’t</h2>)
In the wordpress and drupal db the value is correct. The source is the same.
<h2>When it hasn’t</h2>
I did a search and found many options. None of them helped.
Below are the ones I have done and checked.
1) I double checked that utf-8 is the character encoing in drupal and wp.
I also made a simple test.php file to check nothing else was coming in the way
and it still did not display correctly.
2) I made sure when we take a mysqldump and upload to drupal utf-8
is used.
3) I also made sure the .php file is in utf-8 when saved.
4) I changed the encoding type in chrome for every option available and nothing
displayed it correctly.
5) I also used php functions to recode it but they did not work.
$value2="<h2>When it hasn’t</h2>";
$out = recode_string('..utf-8', $value2);
//output - When it hasnt
$out2= mb_convert_encoding($value2,'UTF-8', "UTF-8");
// output - When it hasn’t
$out3= #iconv('UTF-8', 'utf-8', $value2);
// output - When it hasn’t
I have ran out of options now and I am stuck. Please help
You say the text in both databases is correct, but actually this doesn't mean too much: to viewing the content of a record you must use some client, and quite a few transformations may happen depending on how the text is rendered so you can read it.
So only two things matters:
the encoding of the column
the encoding of the HTML page returned by Drupal
Since your page outputs ’ (in CP1252 is xE2x80x99) for ’ (Unicode U+2019, UTF-8 is 0xE28099) I guess the column is indeed UTF-8, however there's someone between the database and the browser who thinks the text is CP1252. This is what you have to check:
If using MySQL, the connection encoding must be UTF-8 so that what you have in your PHP script is UTF-8 text. You can use SET NAMES 'UTF-8'. Note that if you don't need the Unicode set, you can even use CP1252: the only important thing is that you know the encoding, since PHP strings are just byte arrays.
Explicitely define the response encoding in the HTTP Content-Type header. I mean, configure Drupal to call header('Content-Type: text/html; charset=utf-8');
If the HTTP response encoding is different than the one used for the text retrieved from the db, transcode the query result accordingly
Im trying to get a some data from the db , but the output isn't what i expected.
Doing my own querying on the db , i get this output : string 'C�te d�Ivoire' (length=13)
Querying the db from phpmyadmin i get normal output : Côte d’Ivoire
php.ini default charset, mysql db default charset , <meta> charset are all set to utf-8 .
I can't fugire it out where the encoding is being made that i get different output with same configuration .
P.S. : using mysqli driver .
In the same page that gives you wrong results, try first running this instruction
print base64_encode("Côte");
The correct answer is Q8O0dGU.... If you get something else, like Q/R0ZQo..., this means that your script is working with another charset (here Latin-1) instead of UTF-8. It's still possible that also MySQL and also the browser are playing tricks, but the line above ensures that PHP and/or your editor are playing you false.
Next, extract Côte from the database and output its base64_encode. If you see Q8O0..., then the connection between MySQL and PHP is safely UTF8. If not, then whatever else might also be needed, you need to change the MySQL charset (SET NAMES utf8 and/or ALTER of table and database collation).
If PHP is UTF8, and MySQL is UTF8, and still you see invalid characters, then it's something between PHP and the browser. Verify that the content type header is sent correctly; if not, try sending it yourself as first thing in the script:
Header('Content-Type: text/html; charset=UTF8');
For example in Apache configuration you should have
AddDefaultCharset utf-8
Verify also that your browser is not set to override both server charset and auto-detection.
NOTE: as a rule of thumb, if you get a single diamond with a question mark instead of a UTF8 international character, this means that an UTF8 reader received an invalid UTF8 code point. In other words, the entity showing the diamond (your browser) is expecting UTF8, but is receiving something else, for example Latin1 a.k.a. ISO-8859-15.
Another difficult-to-track way of getting that error is if the output somehow contains a byte order mark (BOM). This may happen if you create a file such as
###<?php
Header("Content-Type: text/html; charset=UTF8");
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF8" />
</head>
<body>
Hellò, world!
</body>
</html>
where that ### is an (invisible in most editors) UTF8 BOM. To remove it, you either need to save the file as "without BOM" if the editor allows it, or use a different editor.
If you do your "own querying" with the command line tool mysql, you have to set the option --default-character-set=utf8, too. Otherwise, please tell us how you do your own querying.
In the osCommerce PHP sources in every script there is a line like this:
<meta http-equiv="Content-Type"
content="text/html; charset=<?php echo CHARSET; ?>
The built-in variable "CHARSET" is very strange and I've never seen this in PHP programming before. I've tried extensive search for "CHARSET php apache encoding charset utf-8 osCommerce" with google, stackoverflow and of course in php.net but couldn't find any results about this PHP variable.
I need further information because it types out unexpected/wrong content which doesn't fit to file encoding, apache transmission encoding nor charset/locale on the system.
So I want to ask: Where does CHARSET get its content from? Do you know any documentation for it?
See: http://forums.oscommerce.com/topic/321294-where-to-define-charset/
Or read it here, as I've copied it from there... :P
Its in catalog/includes/languages/english.php. Change english.php to the language file you need. Look for:
// charset for web pages and emails
define('CHARSET', 'iso-8859-1');