0

I have an app with an input field where you input your name. The app outputs the name on a pdf document with FPDF. As this app is in swedish, many people will input names with special character like å, ä, ö. The input looks like this:

$name = sanitize_text_field(base64_decode($_POST['name']));

And then to:

$specialCharacterName = iconv('UTF-8', 'windows-1252', $name);

It then outputs to FPDF like this:

$pdf->Cell(265,30,' '.$specialCharacterName,0,1,'L',1);

The problem is, as soon as I input a name with a special character, like Björn for example, the output will be blank. But when I input a name without a special character, like Anders, it displays fine.

The strange thing is that when I don't use a variable, and input a string with a special character like this:

$specialCharacterName = iconv('UTF-8', 'windows-1252', 'Björn');

It works fine. The special character is outputted just fine in the PDF document. So there must be something wrong with the variable.

I have also tried utf8_encode() and the result is the same. What am I missing?

Alex
  • 21
  • 4
  • Are you inputing base64 encoded names? if not, why the `base64_decode()`? – Spoody May 23 '18 at 07:08
  • This app is not made by me. I just edit it to fit my own preferences. I don't know why the original creator uses base64_decode(). I guess its for safety purposes? – Alex May 23 '18 at 07:43
  • https://stackoverflow.com/questions/7979567/php-convert-any-string-to-utf-8-without-knowing-the-original-character-set-or – Julio de Leon May 23 '18 at 08:01
  • I checked the database and the special characters do not even get that far. So they are lost before they even get to the ($_POST['name'] it seems. I have also tried adding accept-charset="UTF-8" in the form but that didn't make any difference. – Alex May 23 '18 at 08:37
  • I have noted that the form input goes through a $.ajax() function. I tried adding contentType: "application/x-www-form-urlencoded; charset=UTF-8" but that didn't seem to do anything. – Alex May 23 '18 at 09:34

0 Answers0