Tuesday 26 December 2017

utf 8 - php encoding of posted data changed

I post data from client to php, here is how my post data
seems in client:
rel="nofollow noreferrer"> alt="enter image description here">


I click
add and post this string to php with ajax call here how posted data seem in ajax
parameter;


//username ="Uğur Akkaynak" so
its ok.
var params = {
action: "saveAdObjects",

username_: username,
}
$.ajax({
url:
"../../Controller/ActiveDirectoryController.php5",
type: "POST",

async:false,
dataType: "json",
data: params,
success:
function (result)...

In php file
I check the posted variable:


var user =
$_POST["username"]; //UÄŸur Akkaynak
wtf!

so problem is clear, strings
broken in php, I know I need change encoding in php file and tried
these:


header('Content-type: text/plain;
charset=utf-8');
utf8_encode($_POST["username"]);// Uğur
Akkaynak
mb_convert_encoding ($_POST["username"],'utf-8'); // UÄŸur
Akkaynak

What should I do get
$_POST["username"] as 'Uğur Akkaynak' like posted from client

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...