Jump to content

Displaying all european characters, tried various encodings


Sharkadder

Recommended Posts

Hi,I have recently tried to display some text from a text file which contains some european characters such as turkish ones. When i tried saving text file in ASCI i got a message about illegal characters within it and the european characters got converted the best they could to an asci characters when it saved. I then saved the text file in UTF-8 encoding and it saved the european characters.In php i input the text from the file, i import the text as UTF-8 and some of the characters don't display properly. The text file also contains some English characters and so i need an encoding that will handle both. Below is my PHP attempt:

$lines = file("world.txt", FILE_IGNORE_NEW_LINES);foreach ($lines as $line) {	$line = trim(utf8_decode($line));		print $line;

ok that is my code, within the text file i have the following name (providing the forum allows the characters you will see what i mean):GençlerbirliğiWhen i run normal ASCI encoding within PHP it comes up as follows (question instead of the accented g:Gençlerbirli?iWhen i run UTF-8 encoding as show in the code above i get the following results:Gen?lerbirliğiSo as you can see, asci includes one of the characters but not the other and utf-8 includes the other accented characters but not the other one. Anybody have any idea what i can do to get text from each line of the text file and have the encoding displayed properly? I have also tried getting the above name from a MYSQL database and the value shows up fine, so PHP must be able to handle it ok.p.s. the text file is in UTF-8, i only change the encoding once in php as the characters save to the file ok in UTF-8 but don't display right in php.Thanks,Mark

Link to comment
Share on other sites

Rather than using utf8_decode(), try displaying the content as actual UTF-8:

header('Content-type: text/html;charset=utf-8');$lines = file("world.txt", FILE_IGNORE_NEW_LINES);foreach ($lines as $line) {  $line = trim($line);  echo $line;}

Link to comment
Share on other sites

ok i have tried that but now it said headers have already been sent, any idea how i can force the text to be in utf-8?here is the error on my apache server:Warning: Cannot modify header information - headers already sent by (output started at /home/****/****/****/teams.php:5) in /home/****/****/****/teams.php on line 19Line 19 is the line to set up the header information for UTF-8. I've astrixed some of the link above out so i don't really call the folders ****. ThanksEDITI try with the header code just above my <html> tag and it now works, thanks very much dude.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...