PHP Classes

UTF-8

Recommend this page to a friend!

      AJAX Edit In Place  >  All threads  >  UTF-8  >  (Un) Subscribe thread alerts  
Subject:UTF-8
Summary:Sending UTF8 data to MySQL
Messages:7
Author:Ali
Date:2009-06-27 23:37:25
Update:2009-08-02 08:36:23
 

  1. UTF-8   Reply   Report abuse  
Picture of Ali Ali - 2009-06-27 23:37:25
Hi,
I am using this script on my website.
There is a problem whit sendig data with UTF8 charset.
The form can read UTF8 characters. But in sending and saving to MySQL database, it shows and saves intresting characters like this:

N%u0259zar%u0259t�in istifad%u0259�%u0259r%u0259 yard%u0131m v%u0259 m%u0259sl%u0259h%u0259tl%u0259ri N%u0259zar%u0259t�in N%u0259zar%u0259t�in

Could you help me please.
Thank you.

  2. Re: UTF-8   Reply   Report abuse  
Picture of Er. Rochak Chauhan Er. Rochak Chauhan - 2009-06-29 07:30:26 - In reply to message 1 from Ali
Well solutions is simple, you need to serialize the string before storing the data into the database. Make sure to unserialize the text before displaying on the browser. Just make use of PHP's unserialize() and serialize() functions.

  3. Re: UTF-8   Reply   Report abuse  
Picture of Ali Ali - 2009-06-29 20:42:06 - In reply to message 2 from Er. Rochak Chauhan
Hi,
Thank you for your best script and help.
I found from different sites and I have tried more then 10 unserialize() and serialize() functions.
It gives me different errors in each time.
Could you please help me about this problem.

This is my test page about this problem:
azersayt.com/ajaxeditinplac/php.php

For example if you try any English word, it is okay. But in case of other languages, I have problem.
Ex: əğş
Output: %u0259%u011F%u015F

Here are my source:

edit.php:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
if ($_POST['id'] == 'desc' ) {
//$fp = fopen('text.txt', 'w') or die("Failed to open file for writing.");

include "configat.inc";

$_POST[content] = htmlspecialchars(stripslashes($_POST[content]));


// WRITE TO DATABASE
$queryToWriteToDatabase = ("UPDATE blog SET title = '".$_POST['content']."' WHERE Id='63'");
mysql_query($queryToWriteToDatabase);

$content = $_POST['content'];
echo "$content";

}
?>
=======================
php.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link href="editinplace.css" rel="Stylesheet" type="text/css" />
<script src="prototype.js" type="text/javascript"></script>
<script src="editinplace.js" type="text/javascript"></script>
</head>

<body>

<?php
include "configat.inc";

// READ FROM DATABASE
$queryToReadFromDatabase = ("SELECT * from blog where Id='63'");
$result = mysql_query($queryToReadFromDatabase);
while ($row = mysql_fetch_array($result))
{
//echo $row['title'];

$codeToBeEdited = $row['title'];

$idName1 = 'desc';

require_once('AjaxEditInPlace.inc.php');

$ajaxEditInPlace = new AjaxEditInPlace($codeToBeEdited, $row['title']);
echo $ajaxEditInPlace->getEditInPlaceCode($idName1);

}
?>

</body>
</html>
=============


  4. Re: UTF-8   Reply   Report abuse  
Picture of Er. Rochak Chauhan Er. Rochak Chauhan - 2009-07-05 09:43:48 - In reply to message 3 from Ali
I think this should do the trick:

EDIT.php



<?php
header("Content-Type: text/html");

if ($_POST['id'] == 'desc' ) {
include "configat.inc";
$_POST[content] = htmlspecialchars(stripslashes($_POST[content]));
// WRITE TO DATABASE
$queryToWriteToDatabase = ("UPDATE blog SET title = '".$_POST['content']."' WHERE Id='63'");
mysql_query($queryToWriteToDatabase);

$content = $_POST['content'];
echo "$content";
}
?>

  5. Re: UTF-8   Reply   Report abuse  
Picture of Er. Rochak Chauhan Er. Rochak Chauhan - 2009-07-05 09:45:21 - In reply to message 4 from Er. Rochak Chauhan
PS: Sorry forgot to add UTF..
make it

header("Content-type: "text/html; charset=utf-8");

:)

  6. Re: UTF-8   Reply   Report abuse  
Picture of Ali Ali - 2009-08-02 06:09:40 - In reply to message 5 from Er. Rochak Chauhan
Thank you very much for your help.
I have changed it like your recommended header information’s. But it UTF-8 languages dose not works.
Do you have any other idea please?
Thank you again.

  7. Re: UTF-8   Reply   Report abuse  
Picture of Er. Rochak Chauhan Er. Rochak Chauhan - 2009-08-02 08:36:23 - In reply to message 6 from Ali
Can you please send me a live link so that I can have a look and debug the Ajax Response ?