i need change encode to windows-1256 like this:
print utf8_encode($text)
not ture:
print windows-1256_encode($text)
I had almost the same problem as you do where I wanted to retrieve Arabic data fields from SQL Server 2008 R2 with php using ODBC connection and then I found that getting the right information depends on using " iconv " like this:
echo iconv("","utf-8",$result);
So you can see I didn't mention the first encoding but the way I wanted to display my Arabic data (utf8).
did you try the function mb_convert_encoding
see:
http://www.php.net/manual/en/function.mb-convert-encoding.php and
http://www.php.net/manual/en/mbstring.supported-encodings.php
Alternatively to Stewie's answer you can use the iconv functions.
Related
I'm using PHP5 and OCI 8 with Oracle 11g.
When I fetch a row using oci_fetch_all, the whole result is converted as STRING even for the NUMBER columns and even if I use Oracle's TO_NUMBER in the query.
What I'm trying to do is simple: the javascript calls the PHP script through an Ajax request. The script just fetch some NUMBER data and encode them into JSON. I want the data to be encoded as integer, so the javascript can do math stuff on it (add, divide,..etc) without any conversion.
I am pretty sure that the problem comes from OCI and not JSON encoding because when I VAR_DUMP the result of oci_fetch_all, I can clearly see double quotes on every result:
{
"COLUMN1":"12",
"COLUMN2":"52"
}
I want the result to look like this:
{
"COLUMN1":12,
"COLUMN2":52
}
I tried to:
Change the flag of oci_fetch_all (OCI_FETCHSTATEMENT_BY_ROW, OCI_FETCHSTATEMENT_BY_COLUMN...)
Use oci_fetch_array instead of oci_fetch_all
Remove the UTF8 encoding on the connexion to oracle (I know, its stupid)
The strange thing is that I can't find any thing on the internet about this problem... It's like nobody faced the same issue. Maybe i'm doing something wrong...
Thanks in advance
You can use an extra option in json_encode:
json_encode($rows, JSON_NUMERIC_CHECK);
However this option requires a PHP version of 5.3.3 or higher (thus its ok for you).
All database extensions in PHP work like this, there's nothing you can do about it.
You'll have to manually type-cast the database results.
I use imap_fetchbody to download email from my personal email to a MYSQL DB and when i use with special characters, like accents, in my DB save n? instead of nº for example
Anyone can help me with this problem?
Example:
$data = imap_fetchbody($mbox,$mid,'0');
Best Regards.
This sounds more like a MySQL issue than an IMAP issue.
Try encoding the data as UTF-8. You may also need to specify the character set used by the tables in your database.
try to convert like this $data = imap_qprint(imap_fetchbody($mbox,$mid,'0'));
before the db insertion.
http://php.net/manual/en/function.imap-qprint.php
I connected to to sqlsever2008 with odbc(with dsn) and php but problem is that when I retrieve information from that it has character like ���������. My datatype in sqlserver is nvarchar. Any idea why it is happening?
NOTE: The page is utf8.
Edit:
I use echo utf8_encode(odbc_result($this->result,'name') ); and characters are like:
ÂãæÒÔ ÒÈÇäÂãæÒ
i retrieve information like this:
odbc_result($this->result,'name')
Try to use utf8_decode() or utf8_encode().
It seems, the code page your sql server has been installed is different with your native language. perhaps you need to reinstall the sql server with correct code page.
i found the problem.
iconv("Windows-1256", "UTF-8", "$temp")
I have a problem with utf-8. I use the framework Codeigniter. For a client i have to
convert a CSV file to a database. But when i add the data trough a query to the database
the is a problem. Some characters doesn,t work. For example this word: Eén. When i add this word at PhpMyadmin, it's right.
When i try trought Codeigniter query, it doesn't.
My database stands on Utf-8. The Codeigniter config is utf-8. The database config is on utf-8.
Here is the query:
$query = "INSERT INTO lds_leerdoel(id,leerdoel,kind_omschrijving,cito,groep_id,OCW,opbouw,
kerngebied_id,jaar_maand,KVH,craats,refnivo,toelichting,auteur)
VALUES
(
'".$this->db->escape_str($id)."',
'".$leerdoel."',
'".$this->db->escape_str($kind_omschrijving)."',
'".$this->db->escape_str($cito)."',
'".$this->db->escape_str($groep_id)."',
'".$this->db->escape_str($OCW)."',
'".$this->db->escape_str($opbouw)."',
'".$this->db->escape_str($kerngebied_id)."',
'".$this->db->escape_str($jaar_maand)."',
'".$this->db->escape_str($KVH)."',
'".$this->db->escape_str($craats)."',
'".$this->db->escape_str($refnivo)."',
'".$this->db->escape_str($toelichting)."',
'".$this->db->escape_str($auteur)."'
)";
$this->db->query($query);
The problem is the field leerdoel. Does somebody a solution. Thank you verry much!!
Greetings,
Jelle
You'll need to run this query before the insert query
"SET NAMES utf8"
Shouldn't you use a national character string literal? http://dev.mysql.com/doc/refman/5.0/en/charset-national.html
Meaning that you would write:
$query = "INSERT INTO lds_leerdoel(id,leerdoel,kind_omschrijving,cito,groep_id,OCW,opbouw,
kerngebied_id,jaar_maand,KVH,craats,refnivo,toelichting,auteur)
VALUES
(
'".$this->db->escape_str($id)."',
N'".$leerdoel."',
-- rest of query omitted
Try to convert the text to Unicode with iconv():
iconv( "ISO-8859-1", "UTF-8", $leerdoel );
You might need to experiment a little if you don't know what encoding the file uses. (I think ISO-8859-1 or ISO-8859-15 are the most common.)
Try adding this to your header
header('Content-Type: text/html; Charset=UTF-8');
Also check the encoding settings of your editor.
I had a similar problem and i solve adding this in the beginning of my PHP file:
ini_set('default_charset', 'UTF-8');
mb_internal_encoding('UTF-8');
Additionally, is very important to check if you are saving your PHP file in UTF-8 format without BOM, i had a big headache with this. I recomend Notepad++, it shows the current file encoding and allow you to convert to UTF-8 without BOM if necessary.
If you would like to see my problem and solution, it is here.
Hope it can help you!
i realized when i used urlencode or rawurlencode in PHP encoding the simple character § (paragraph) i get the following result: "%C2%A7".
But when i use escape in Javascript to encode that character, i get only "%A7".
In this case i have encoding problems when sending/receiving data between the server running PHP and the javascript client trying to fetch the data via ajax/jquery.
I want to be able to write any type of text i want. For this i encode the text and send it to the backend php script, escaping the data and sending. When i retrieve it, on php side i take the data from mysql and do rawurlencode and send it back.
Both sides, work in UTF-8 mode. jquery ajax function is called with "contentType: application/x-www-form-urlencoded:charset=UTF-8", mysql server is set for UTF-8 both for client and server, and the php script starts echoing with header( "application/x-www-form-urlencoded:charset=UTF-8");
Why is PHP producing that %C2 thing, which generates the character  on javascript side.
Coult somebody help?
I had the same problem a while ago and found the solution :
function rawurlencode (str) {
str = (str+'').toString();
return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
replace(/\)/g, '%29').replace(/\*/g, '%2A');
}
The code is taken from here - http://phpjs.org/functions/rawurlencode:501
Hope it helps.
It's clearly a charset íssue:
[adrian#cheops3:~]> php -r 'echo rawurlencode(utf8_encode("§"));'
%C2%A7
[adrian#cheops3:~]> php -r 'echo rawurlencode("§");'
%A7
(the terminal is obviously not running in utf8 mode)
If you have a literal § in your PHP code ensure that the php file is saved as UTF8.