I want to read arabic characters from to text file and show them
but they are shown in a strange symbols like �
and they can't be compared with any characters
Let try to work on it together :
I will assume you code looks like :
1- your file should written in UTF8 encoding , i will take care if it's not
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<?php
$file_path = "c:/home/user/text.txt";
$data = file_get_contents($file);
// if its utf8 file skip this line
$arabic_data = iconv("windows-1256" , "utf8" , $data);
echo $arabic_data ; ?>
in case you are linux user you can use iconv in commandline much powerful & easier
I'll update my answer in case you need more help or provide more info
Try to create .htaccess file in the root of your web application and write such string there AddDefaultCharset UTF-8
You need to know the encoding of these files. Can be UTF-8, can be some transliteracion, can be something else. Then you have to convert to UTF-8 (not needed if are already utf-8), then you output that as in the page,... having the page declare itself as UTF-8... Like the Mira comment.
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
is life saver
if you working with php, use
echo '<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />';
in you scrip
Change file encoding to UTF-8
By open file by using any editor and change encode from editor to utf-8
Related
I have a website where the web pages feed from the same database and I found that in two webpages that have same queries they interpretate the spanish special characters differently.
I cant really figure out what is wrong as I have stripped out the code which is interpreting the special spanish characters wrong and building it up from the scratch.
This one interpretes the characters well.
http://amragl.com/
This one interpretes the characters wrong.
http://amragl.com/menu.php
They both have the following
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
They both feed from the same database and use same queries.
Does anyone have any idea of how to fix this problem?
Thanks in advance.
--UPDATE-
PEASE SEE THE WORD "GAZPACH" or "AL LIM" to see the difference.
You have both
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
in the same file.
I suggest only using the utf-8 one.
Change iso-8859-1 to utf-8, should fix it.
The menu.php page is rendering with windows-1252 encoding, even tho it has iso-8859-1 set.
Are the menu.php contents coming from a database? If yes, which encoding is the database using?
I'm trying to print a string, like this:
Noticias de Fútbol.
But when I print this string, it displays like this:
Noticias de F�tbol.
I tried htmlspecialchar() and many more, but my output remains the same.
$str = "Noticias de Fútbol";
$strfoot = html_entity_decode($str);
How can I resolve this?
You don't need to use html_entity_decode, you can just simply print out your $str with echo, but you have to make sure your html has this line of code in the <head>:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
You have use charset utf 8 and htmlentities function of php
Like
<meta http-equiv="content-type" content="text/html; charset=utf-8">
$test=htmlentities("Sisälämpötila");
echo $test;
You are most likely outputting to a page that has the wrong charset specified. To confirm this open a JavaScript console and evaluate window.document.charSet and window.document.characterSet.
If that is the case you can use a meta tag to inform the browser of your intended charset:
<meta content="text/html; charset=utf-8">
I'm reading elsewhere the tag might be:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
Your php file is not utf-8 but the browser is reading it as utf-8 which is giving you that question mark character. Save your file as utf-8, most editors/ides have options to set the charset of the file.
This may be a stupid question but its not a matter of what I can find, its a matter that I dont know what to search for. There are some special characters that don't show correctly in php. I'm taking some information from an xml file, and echo-ing them.
ie:
should be -> Nürnberg
echoes as -> Nürnberg
any tips on what to look for, or how to resolve this?
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
You simply have an encoding mismatch. Get up to speed with these articles:
What Every Programmer Absolutely, Positively Needs To Know About Encodings And Character Sets To Work With Text
Handling Unicode Front To Back In A Web App
try a different character set on the page you're echoing from
http://www.w3schools.com/tags/ref_charactersets.asp
Can you try with following meta tag in your HTML head.
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
There is a mismatch between the character encoding of your XML and what you are outputting from PHP. Most likely, one is UTF-8 and one is ISO-8859.
On the PHP side, you can set this with a header directive
<?php
header('Content-Type: text/plain; charset=ISO-8859-1');
header('Content-Type: text/plain; charset=utf-8');
?>
and/or in the outputted HTML
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
On the XML side, most quality text editors allow you to specify the character encoding as you save the file. (E.g. WordWrangler on Mac)
If the XML file is indeed in ISO-8859, you could use utf8_encode() to convert it to UTF-8 as you read it in.
An in-depth discussion of PHP and character encoding.
"I'm taking some information from an xml file, and echo-ing them."
Windows command line doesn't support utf8 properly as it doesn't use an UTF8 font.
Just put the file into somewhere that's reachable through a web server and test it by calling the file through the web server.
Alternatively pipe the output of the script into a text file:
php test.php > output.txt
And either open output.txt is a UTF8 capable editor or use a utf8 capable 'Tail' program.
Test.php
<?php
echo "Nürnberg";
?>
Running from command prompt:
php test.php
Nürnberg
Calling through a web server http://localhost/test.php
Nürnberg
I'm having some trouble with my page. I have moved my site from a host provider to another one, and now i'm having some problems with non-latin characters, for text that comes from db query and for text that is in html/php file.
For text that comes from db someone suggested me to apply this after db connection:
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET NAMES utf8");
and it did the trick, but, now i'm having the same problem for texts that comes from html/php files: instead of ë or ç appears �
I'm sure that should be e trick someone on the server or somewhere else on the configuration.
Hope that you can help me.
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
i'm using at the header of my file.
You must have this line in your <head> section:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Is the collation of your database where the data is stored in utf8_general_ci?
Maybe there was a problem while transfering the files.
If you are familiar with Linux, try to fix the broken files on your server with recode
(excerpt: "The Recode library converts files between character sets and usages.")
When I pass a string with special characters to my view, The special characters are shown as a question mark, eg:
$data['make'] = 'Quels pneus Dunlop avez-vous acheté ?';
$this->load->view("form", $data);
This looks as follows in my view:
When I type the characters directly into the HTML page they show fine. how can I fix this issue?
EDIT: The charset is already set to:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
Using codeigniters ascii_to_entities function did the trick.
$this->load->helper('text');
ascii_to_entities($string);
Looks like it could be a charset conflict. Make your HTML charset declaration UTF8 and save your data as UTF8 in the database or text file.
In your <head> tag:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
If you are using htmlentities() to output the data var then consider specifying the character set there as well.
echo htmlentities($str, ENT_COMPAT, 'UTF-8');
Save your view page as utf8 and that will do the job