Smarty special character issue - php

I used spanish language in my site. when iinserted the character like í,á,é,ó it will insert properly in db,but it cannot display in front-end, it display like this � in front-end
for example :
Insert name : Test teachér in database it inserted correctly but in front it display as
Test teach�r.
i used <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
also but no changes at all.

It has nothing to do with smarty.
Check db charset where you store data and set it to UTF-8 General CI
Check charset of db connection SET NAMES utf8
Check the output of script if it's in UTF you can do it with meta charset, or in headers content-type.
Content-type: text/html; charset="UTF-8"
or
<meta charset="utf-8"> or <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
After these operations you should have proper output.
You can also optionally check if functions that work on strings supports UTF-8.

Related

Some characters become "�" in our webpage

I use PHP to access a database to get a string like this
‘Chloe’ Fashion Show & Dinner
and then I do a printf() to output the string as html, but my webpage shows this:
�Chloe� Fashion Show & Dinner
All contents are English-based, do I miss something in PHP?
Where should I be checking?
Check if your .php file is encoded as UTF-8 without BOM
Check that your connection to the database is UTF-8
Check that you send <meta charset="utf-8"> in your HTML markup in the <head> tag
If your connection to the database is not UTF-8 and you don't want to change it (but I recommend it -> everything UTF-8 is the most secure solution against character rubbish) use utf8_encode($databaseValue) to ensure the encoding of your value is UTF-8.
Make sure that you use:
<meta charset="utf-8">
in the head of your page.
You need to add charset meta tag in 'head' section of html.
Note that the meta tag must appear within the first 1024 bytes of rendered page.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

UTF-8 French accented characters issue

When i see data as stored on mysql database using phpmyadmin, the characters are stored exactly as é à ç however when i use php to display these data on an html document that has the exact following structure:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
</body>
</html>
I got square instead of accented character, however, i don't have this issue with any accented characters on static content that haven't been loaded from mysql in the same page.
when i see on the source code of the page they seem to be identical! for example:
part of static data on the source code displayed as:
éçà
part of mysql origin data:
éçà
i tried replacing
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
with
<meta http-equiv="Content-Type" content="text/html; charset=windows-1552" />
and as result i got mysql one fixed, static with squares !
any hints?
This is quite common charset issue, you need to set connection encoding manually for MySQL connection (those should be first queries you execute after establishing connection):
SET NAMES utf8;
SET CHARACTER SET utf8;
And also make sure every table has CHARACTER SET set to UTF-8.
Or you could also update server configuration.
Looks like a misconfiguration issue. Most probably your DB or drivers are not using UTF-8.
The fact that the data that comes from the DB shows OK when you change to windows-1552 and the static files do not can mean that your source file is (correctly) in UTF-8, but the data from your DB is arriving in the wrong encoding format.
Whatever is going on, stick to UTF-8.
UPDATE: There is a thread that explains how to automatically set the encoding for the connection:
Change MySQL default character set to UTF-8 in my.cnf?

How can I print special HTML characters correctly, using PHP?

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.

How to set an specific character set?

I'm using Excel to send information to my MySQL database. That contains several 'Ø' character. My database is set to utf8_general_ci and the website to <meta http-equiv="content-type" content="text/html; charset=utf-8" />
When I use an text field to edit the database all 'Ø' characters are changed to '?' in the text field, how can I prevent this from happening?
Have you set the mysql connection encoding? In php you do it with mysql_set_charset("utf8").
If the data in the database is correct, then you need to ensure that the connection between your php script and the database is also UTF-8 by issuing
In mysqli do
$mysqli->set_charset("utf8")
or in mysql do
mysql_set_charset("utf8")
And ensure that your html is also set to utf-8 by adding this tag to header
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Web page text display problem

I keep getting these weird text characters when I display user submitted text. like in the following example below. Is there a way I can fox this using PHP, CSS or something so that the characters are displayed properly?
Here is the problem text.
Problems of �real fonts� on the web. The one line summary:
different browsers and different platforms do �hinting�
Here is my meta tag.
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
It's an encoding problem. Make sure you send the correct encoding to the browser. If it's UTF-8, you'll do it like this:
header("Content-type: text/html; charset=utf-8");
Also, make sure that you store the content using the same encoding throughout the entire system. Set your database tables to utf8. If you're using MySQL, run the SET NAMES utf8 query when connecting to make sure you're running in UTF-8.
These weird characters occur when you suddenly switch encoding.
Also, some functions in PHP take a $charset parameter (e.g. htmlentities()). Make sure you pass the correct charset to that one as well.
To make sure that PHP handles your charset correctly in all cases, you can set the default_charset to utf-8 (either in php.ini or using ini_set()).
Set your page to UTF-8 encoding.
Please check with the char-set in header section.
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
use this below one:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
or try this one:
htmlentities($str, ENT_QUOTES);
Could be problem with file encoding please check that your files is correctly encoded, saved as "UTF-8 without boom", also if you are saving to database use SET NAMES UTF-8

Categories