Hebrew fonts is not showing - php

I have an API in which i am showing some videos of english and hebrew. Its all running fine except the title written in Hebrew language is not showing instead of it its returning sign of "??"
Any idea ??

Make sure you are serving UTF-8 by adding <meta charset="UTF-8" /> in between your head tag.
Make sure the database content is UTF-8. If it's not UTF-8, you'll need to convert the database data from the encoding used in the database to UTF-8 before you push it to the web browsing client like this: $str = mb_convert_encoding($str, "UTF-8", "DATABASE-ENCODING-USED"); More info and examples: http://php.net/manual/en/function.mb-convert-encoding.php
One of both will be the solution to your the problem.
Update
Might be far-fetched, but make sure your browser is able to display a hebrew font type too.
In fact, you don't tell us how you check your database (with a client or via browser) and we don't know how you test the display.
To avoid any "hidden" errors in your debugging efforts, try this code:
<?php
/*
Make sure the web browser receives a header telling it there's UTF-8 inside.
*/
header('Content-Type: text/html; charset=UTF-8');
/*
Write a title that will display correctly
if there's no font-related issue in your browser.
*/
echo('<h1>זהו מבחן.</h1>');
/*
Now connect to database,
and use a simple SELECT to fetch something from the database.
Replace YOUR-MYSQL-USERNAME, YOUR-MYSQL-PASSWORD and YOUR-MYSQL-DATABASE
with your individual values...
*/
$dbh = mysql_connect("localhost","YOUR-MYSQL-USERNAME","YOUR-MYSQL-PASSWORD");
if(!$dbh)
{
exit('Could not connect: ' . mysql_error());
}
$result = mysql_query('SELECT * FROM YOUR-MYSQL-DATABASE LIMIT 1',$dbh);
mysql_close($dbh);
/*
Now dump it nicely to the screen and exit.
*/
echo('<pre>');
var_dump($result);
echo('</pre>');
exit();
?>
That will help you nailing down the problem.
If it does not show your Hebrew fonts nicely, it's most probably a font-and-browser issue.
In any other case, your database is not UTF-8 and you will need to convert using *mb_convert_encoding* or alike - as I explained above.

Have you encoded your HTML document to accept them?
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<html lang="he">
...
</html>

If the data is coming from the database, you want to make sure that you're retrieving it with the right encoding. If possible, you should run a SET NAMES query before the query (either SET NAMES 'utf8' or SET NAMES 'hebrew', depending on the collation in the DB).

Related

can't save arabic in php variable?

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"

Why does my output change?

I'm working with UTF-8 encoding in PHP and I keep managing to get the output just as I want it. And then without anything happening with the code, the output all of a sudden changes.
Previously I was getting hebrew output. Now I'm getting "&&&&&".
Any ideas what might be causing this?
These are most common problems:
Your editor that you’re creating the PHP/HTML files in
The web browser you are viewing your site through
Your PHP web application running on the web server
The MySQL database
Anywhere else external you’re reading/writing data from (memcached, APIs, RSS feeds, etc)
And few things you can try:
Configuring your editor
Ensure that your text editor, IDE or whatever you’re writing the PHP code in saves your files in UTF-8 format. Your FTP client, scp, SFTP client doesn’t need any special UTF-8 setting.
Making sure that web browsers know to use UTF-8
To make sure your users’ browsers all know to read/write all data as UTF-8 you can set this in two places.
The content-type tag
Ensure the content-type META header specifies UTF-8 as the character set like this:
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
The HTTP response headers
Make sure that the Content-Type response header also specifies UTF-8 as the character-set like this:
ini_set('default_charset', 'utf-8')
Configuring the MySQL Connection
Now you know that all of the data you’re receiving from the users is in UTF-8 format we need to configure the client connection between the PHP and the MySQL database.
There’s a generic way of doing by simply executing the MySQL query:
SET NAMES utf8;
…and depending on which client/driver you’re using there are helper functions to do this more easily instead:
With the built in mysql functions
mysql_set_charset('utf8', $link);
With MySQLi
$mysqli->set_charset("utf8")
*With PDO_MySQL (as you connect)*
$pdo = new PDO(
'mysql:host=hostname;dbname=defaultDbName',
'username',
'password',
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
);
The MySQL Database
We’re pretty much there now, you just need to make sure that MySQL knows to store the data in your tables as UTF-8. You can check their encoding by looking at the Collation value in the output of SHOW TABLE STATUS (in phpmyadmin this is shown in the list of tables).
If your tables are not already in UTF-8 (it’s likely they’re in latin1) then you’ll need to convert them by running the following command for each table:
ALTER TABLE myTable CHARACTER SET utf8 COLLATE utf8_general_ci;
One last thing to watch out for
With all of these steps complete now your application should be free of any character set problems.
There is one thing to watch out for, most of the PHP string functions are not unicode aware so for example if you run strlen() against a multi-byte character it’ll return the number of bytes in the input, not the number of characters. You can work round this by using the Multibyte String PHP extension though it’s not that common for these byte/character issues to cause problems.
Taken form here: http://webmonkeyuk.wordpress.com/2011/04/23/how-to-avoid-character-encoding-problems-in-php/
Try after setting the content type with header like this
header('Content-Type: text/html; charset=utf-8');
Try this function - >
$html = "Bla Bla Bla...";
$html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
for more - http://php.net/manual/en/function.mb-convert-encoding.php
I put together this method and called it in the file I'm working with, and that seemed to resolve the issue.
function setutf_8()
{
header('content-type: text/html; charset: utf-8');
mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');
mb_http_input('UTF-8');
mb_language('uni');
mb_regex_encoding('UTF-8');
ob_start('mb_output_handler');
}
Thank you for all your help! :)

How to set the charset to UTF-8 for a received http variable in PHP?

How to set the charset to UTF-8 for a received http variable in PHP?
I have a html form using the POST methode with 1 input field. But when i submit the form and echo the retrieved the contents from the input field via $_POST['input_name'] i get this: KrkiÄ - but i entered (and i need) this: Krkič
So how can i fix this?
I figured it out now. :)
If i want to add the contents to MYSQL then i need to add this:
if(!$mysqli->set_charset("utf8")){
printf("Error loading character set utf8: %s\n",$mysqli->error);
}
If i just need to echo the contents then adding this meta tag
<meta charset="utf-8">
into html head is enough.
There is no global default charset in PHP -- lots of things are encoding-aware, and each needs to be configured independently.
mb_internal_encoding applies only to the multibyte string family of functions, so it has an effect only if you are already using them (you need to do so most of the time that you operate on multibyte text from PHP code).
Other places where an incorrectly set encoding will give you problems include:
The source file itself (saved on the disk using which encoding?)
The HTTP headers sent to the browser (display the content received as which encoding?)
Your database connection (which encoding should be used to interpret your queries? which encoding for the results sent back to you?)
Each of these needs to be addressed independently, and most of the time they also need to agree among themselves.
Therefore, it is not enough to say "I want to display some characters". You also need to show how you are displaying them, where they are coming from and what the advertised encoding is for your HTML.
you can use:
<meta charset="UTF-8" />
on top of your php file place this
header('Content-Type: text/html; charset="UTF-8"');

Same dataset outputs different characters : phpmyadmin / own query

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.

UTF-8 display-issues in PhpMyAdmin-Gui

I've got the following problem with my PMA-GUI:
While the data submitted by PHP-Scripts to my database is displayed correctly, ONLY PMA displays several german Umlaut's (such as äüß, ..) as ü or ä
The problem occurs also while exporting tables to file..
MySQL: 5.0.51a-3ubuntu5.8
PMA: 3.4.5
Database & fields are utf8_general_ci
Does anybody know a solution?
Are you sure that your client is sending data as utf-8?
this seems to me a duplicate of:
German Umlaute in Mysql/Phpmyadmin
You need to ensure you use consistent use of character set/character encoding.
For example, to normalise to UTF-8 content, your DB fields' character sets should be set to UTF-8. Then, in your PHP (if you have your own scripts running that fetch DB information) you need to then add to the head section:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Then, in the PHP, before any output to the browser, include the content type PHP header:
header ('Content-type: text/html; charset=utf-8');
Before you run any SQL to fetch content (so after you connect, but before executing your query), use mysql_set_charset:
mysql_set_charset('utf8',$link);
// $link is optional, refers to your DB connection
You can think of it as three steps:
The step used to add the characters to your DB
Storage of characters in your DB
Retrieval and display of characters
The simplest bet to ensure conformity and that characters display as you anticipate, is to ensure the correct, consistant, character set is defined at each stage.

Categories