I have a really big problem with saving data from Flash as2 to database. I tried solved it myself, read many topics on different forums but no result.
I have an Input Text field (mess_txt
) in as2 project and Send button with the next code:
on(release){
var formData = new LoadVars();
formData.etext = mess_txt.text;
formData.sendAndLoad("sendmail.php", formData, "POST");
formData.onLoad = function(){
// receive actions...
}
}
Code in sendmail.php:
include("connect.php");
$text = $_POST['etext'];
$text = str_replace("\r", "<br/>", trim(strip_tags($text)));
$text = str_replace("\n", "", $text);
$text = str_replace("\"", """, $text);
$text = str_replace("'", "'", $text);
$query = "insert into reviews (text, status) values ('".$text."', 'new')";
mysql_query($query) or die (mysql_error());
mail("mail@gmail.com", "Title!", "Message text: ".$text);
When I use latin symbols both code works well but when I input cyrillic symbols in Input Text I have an empty string in PHP code.
In Input Text I use _self
font and embed all glyphs. But I think that problem is in sending data because when send simple cyrillic string instead mess_txt.text
I have an empty string as well.
Interesting, that when I used mb_detect_encoding($_POST['etext'])
in PHP code I obtained ASCII not UTF
Please, help me!!!!
SOLVED!!!
I found how to solve this problem! May be it will be interesting for someone else...
Before sending data from as2 to php I transformed it from text to unicode codes. This is my function in as2 project:
on(release){
var txt = getRealText(mess_txt.text);
var formData = new LoadVars();
formData.etext = txt;
formData.sendAndLoad("sendmail.php", formData, "POST");
formData.onLoad = function(){
// receive actions...
}
function getRealText(str){
var newStr = "";
for(i=0, s=str.length; i<s; i++){
newStr += "&#"+ord(str.charAt(i))+";";
}
return newStr;
}
}
As result I sending string "тест
" instead "тест
".
In PHP file I received this string:
$text = html_entity_decode($_POST['etext'], ENT_NOQUOTES, 'UTF-8');
After that I obtained normal cyrillic (or any another) text.
Have a hope that this will be useful for someone!